Støtte for å lage kommentarer i fileformat.py.
This commit is contained in:
parent
337cba493a
commit
66908ccf02
|
@ -1,3 +1,5 @@
|
||||||
|
import types
|
||||||
|
|
||||||
fields = {
|
fields = {
|
||||||
'book':
|
'book':
|
||||||
[('isbn', 's'), ('title', 's'), ('category', 's'),
|
[('isbn', 's'), ('title', 's'), ('category', 's'),
|
||||||
|
@ -75,9 +77,18 @@ def write_field_value_list(val):
|
||||||
lines += ' ' + unicode(single_value)
|
lines += ' ' + unicode(single_value)
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
def make_comment(s):
|
||||||
|
return '\n'.join(map(lambda x: '# ' + x,
|
||||||
|
s.split('\n'))) + '\n'
|
||||||
|
|
||||||
def write_action(d):
|
def write_action(d):
|
||||||
|
if type(d) in types.StringTypes:
|
||||||
|
return make_comment(d)
|
||||||
|
lines = ''
|
||||||
|
if 'comment' in d:
|
||||||
|
lines += make_comment(d['comment'])
|
||||||
action = d['action']
|
action = d['action']
|
||||||
lines = 'action: ' + action + '\n'
|
lines += 'action: ' + action + '\n'
|
||||||
data_type = action_fields[action]['type']
|
data_type = action_fields[action]['type']
|
||||||
for field, ftype in fields[data_type]:
|
for field, ftype in fields[data_type]:
|
||||||
if field in d:
|
if field in d:
|
||||||
|
@ -90,4 +101,4 @@ def write_action(d):
|
||||||
def write_actionlist(actions):
|
def write_actionlist(actions):
|
||||||
return '\n'.join(map(write_action, actions))
|
return '\n'.join(map(write_action, actions))
|
||||||
|
|
||||||
# test: print write_actionlist([{'action':'new-book','isbn':'434545'},{'action':'edit-book','isbn':'654654745','persons':{'author':['ab','foo'],'illustrator':['moo']}},{'action':'edit-category','id':'matematikk','name':'Matematikk','placement':['T10','T11']}])
|
# test: print write_actionlist([{'comment':'Foo!\nBar!','action':'new-book','isbn':'434545'},{'action':'edit-book','isbn':'654654745','persons':{'author':['ab','foo'],'illustrator':['moo']}},'This\nis\na\ncomment.',{'action':'edit-category','id':'matematikk','name':'Matematikk','placement':['T10','T11']}])
|
||||||
|
|
Reference in New Issue