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

Litt dokumentasjon og fiksing i fileformat.py.

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-03-05 20:45:28 +00:00
parent d79e5299af
commit 1476dcfc4b
1 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,10 @@
import types
# The possible fields for each type of object.
#
# Each field is a tuple (fieldname, fieldtype). Fieldtype is either
# 's' (string), 'd' (dictionary, where the values are lists of
# strings), 'l' (list of strings).
fields = {
'book':
[('isbn', 's'), ('title', 's'), ('category', 's'),
@ -11,6 +16,12 @@ fields = {
[('id', 's'), ('first_name', 's'), ('last_name', 's')],
'category':
[('id', 's'), ('name', 's'), ('placement', 'l')] }
# Fields associated with each action.
#
# The 'type' is a key in the fields dictionary, indicating the set of
# fields which can be used with the action. The 'required' list is a
# list of fields which must be present for the action to be accepted.
action_fields = {
'new-book':
{ 'type': 'book',
@ -40,18 +51,25 @@ action_fields = {
{ 'type': 'category',
'required': ['id'] } }
class CommitFormatSyntaxError(Exception):
pass
def read_action(lines):
d = {}
lastfield = None
for line in lines:
if len(line) == 0:
raise 'Empty line in action'
raise CommitFormatSyntaxError('Empty line in action')
if line[0] in [' ', '\t']: # continuation line
if not lastfield:
raise 'First line is continuation line'
raise CommitFormatSyntaxError('First line is continuation line: ' + line)
d[lastfield] = d[lastfield] + '\n' + line.strip()
else:
field, value = line.split(':', 1)
# reader = { 's': read_field_value_str,
# 'd': read_field_value_dict,
# 'l': read_field_value_list }[
# translated_value =
# TODO skriv ferdig
def write_field_value_str(val):