# HG changeset patch # User Paul Boddie # Date 1454946722 -3600 # Node ID 84c6d38d2c9aff3d160548fc0914fa33b99e690d # Parent 5a9722130d257d6227fedbbc529f0f792c690a88 Support the more flexible text format for the groups and limits files. diff -r 5a9722130d25 -r 84c6d38d2c9a imip_store.py --- a/imip_store.py Mon Feb 08 16:35:06 2016 +0100 +++ b/imip_store.py Mon Feb 08 16:52:02 2016 +0100 @@ -25,6 +25,7 @@ from imiptools.dates import format_datetime, get_datetime, to_timezone from imiptools.filesys import fix_permissions, FileBase from imiptools.period import FreeBusyPeriod +from imiptools.text import parse_line from os.path import isdir, isfile, join from os import listdir, remove, rmdir from time import sleep @@ -50,7 +51,7 @@ t[i] = default return t - def _get_table(self, user, filename, empty_defaults=None): + def _get_table(self, user, filename, empty_defaults=None, tab_separated=True): """ From the file for the given 'user' having the given 'filename', return @@ -59,13 +60,21 @@ The 'empty_defaults' is a list of (index, value) tuples indicating the default value where a column either does not exist or provides an empty value. + + If 'tab_separated' is specified and is a false value, line parsing using + the imiptools.text.parse_line function will be performed instead of + splitting each line of the file using tab characters as separators. """ f = codecs.open(filename, "rb", encoding="utf-8") try: l = [] for line in f.readlines(): - t = line.strip(" \r\n").split("\t") + line = line.strip(" \r\n") + if tab_separated: + t = line.split("\t") + else: + t = parse_line(line) if empty_defaults: t = self._set_defaults(t, empty_defaults) l.append(tuple(t)) @@ -73,7 +82,7 @@ finally: f.close() - def _get_table_atomic(self, user, filename, empty_defaults=None): + def _get_table_atomic(self, user, filename, empty_defaults=None, tab_separated=True): """ From the file for the given 'user' having the given 'filename', return @@ -82,11 +91,15 @@ The 'empty_defaults' is a list of (index, value) tuples indicating the default value where a column either does not exist or provides an empty value. + + If 'tab_separated' is specified and is a false value, line parsing using + the imiptools.text.parse_line function will be performed instead of + splitting each line of the file using tab characters as separators. """ self.acquire_lock(user) try: - return self._get_table(user, filename, empty_defaults) + return self._get_table(user, filename, empty_defaults, tab_separated) finally: self.release_lock(user) @@ -958,7 +971,7 @@ if not filename or not isfile(filename): return {} - return dict(self._get_table_atomic(quota, filename)) + return dict(self._get_table_atomic(quota, filename, tab_separated=False)) def get_limits(self, quota): @@ -971,7 +984,7 @@ if not filename or not isfile(filename): return None - return dict(self._get_table_atomic(quota, filename)) + return dict(self._get_table_atomic(quota, filename, tab_separated=False)) # Free/busy period access. diff -r 5a9722130d25 -r 84c6d38d2c9a tests/test_resource_invitation_constraints_quota.sh --- a/tests/test_resource_invitation_constraints_quota.sh Mon Feb 08 16:35:06 2016 +0100 +++ b/tests/test_resource_invitation_constraints_quota.sh Mon Feb 08 16:52:02 2016 +0100 @@ -40,7 +40,7 @@ EOF mkdir -p "$JOURNAL/$QUOTA" -echo '*\tPT1H' > "$JOURNAL/$QUOTA/limits" +echo '* PT1H' > "$JOURNAL/$QUOTA/limits" "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-car.txt" 2>> $ERROR \ | "$SHOWMAIL" \ @@ -118,7 +118,7 @@ # Increase the quota. -echo '*\tPT2H' > "$JOURNAL/$QUOTA/limits" +echo '* PT2H' > "$JOURNAL/$QUOTA/limits" # Attempt to schedule the event again.