Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

Støtte for å lage kommentarer i fileformat.py.

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-03-05 19:31:31 +00:00
parent 337cba493a
commit 66908ccf02
1 changed files with 13 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import types
fields = {
'book':
[('isbn', 's'), ('title', 's'), ('category', 's'),
@ -75,9 +77,18 @@ def write_field_value_list(val):
lines += ' ' + unicode(single_value)
return lines
def make_comment(s):
return '\n'.join(map(lambda x: '# ' + x,
s.split('\n'))) + '\n'
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']
lines = 'action: ' + action + '\n'
lines += 'action: ' + action + '\n'
data_type = action_fields[action]['type']
for field, ftype in fields[data_type]:
if field in d:
@ -90,4 +101,4 @@ def write_action(d):
def write_actionlist(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']}])