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 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 = { fields = {
'book': 'book':
[('isbn', 's'), ('title', 's'), ('category', 's'), [('isbn', 's'), ('title', 's'), ('category', 's'),
@ -11,6 +16,12 @@ fields = {
[('id', 's'), ('first_name', 's'), ('last_name', 's')], [('id', 's'), ('first_name', 's'), ('last_name', 's')],
'category': 'category':
[('id', 's'), ('name', 's'), ('placement', 'l')] } [('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 = { action_fields = {
'new-book': 'new-book':
{ 'type': 'book', { 'type': 'book',
@ -40,18 +51,25 @@ action_fields = {
{ 'type': 'category', { 'type': 'category',
'required': ['id'] } } 'required': ['id'] } }
class CommitFormatSyntaxError(Exception):
pass
def read_action(lines): def read_action(lines):
d = {} d = {}
lastfield = None lastfield = None
for line in lines: for line in lines:
if len(line) == 0: if len(line) == 0:
raise 'Empty line in action' raise CommitFormatSyntaxError('Empty line in action')
if line[0] in [' ', '\t']: # continuation line if line[0] in [' ', '\t']: # continuation line
if not lastfield: if not lastfield:
raise 'First line is continuation line' raise CommitFormatSyntaxError('First line is continuation line: ' + line)
d[lastfield] = d[lastfield] + '\n' + line.strip() d[lastfield] = d[lastfield] + '\n' + line.strip()
else: else:
field, value = line.split(':', 1) 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 # TODO skriv ferdig
def write_field_value_str(val): def write_field_value_str(val):