1.1 --- a/imip_store.py Mon Feb 08 16:35:06 2016 +0100
1.2 +++ b/imip_store.py Mon Feb 08 16:52:02 2016 +0100
1.3 @@ -25,6 +25,7 @@
1.4 from imiptools.dates import format_datetime, get_datetime, to_timezone
1.5 from imiptools.filesys import fix_permissions, FileBase
1.6 from imiptools.period import FreeBusyPeriod
1.7 +from imiptools.text import parse_line
1.8 from os.path import isdir, isfile, join
1.9 from os import listdir, remove, rmdir
1.10 from time import sleep
1.11 @@ -50,7 +51,7 @@
1.12 t[i] = default
1.13 return t
1.14
1.15 - def _get_table(self, user, filename, empty_defaults=None):
1.16 + def _get_table(self, user, filename, empty_defaults=None, tab_separated=True):
1.17
1.18 """
1.19 From the file for the given 'user' having the given 'filename', return
1.20 @@ -59,13 +60,21 @@
1.21 The 'empty_defaults' is a list of (index, value) tuples indicating the
1.22 default value where a column either does not exist or provides an empty
1.23 value.
1.24 +
1.25 + If 'tab_separated' is specified and is a false value, line parsing using
1.26 + the imiptools.text.parse_line function will be performed instead of
1.27 + splitting each line of the file using tab characters as separators.
1.28 """
1.29
1.30 f = codecs.open(filename, "rb", encoding="utf-8")
1.31 try:
1.32 l = []
1.33 for line in f.readlines():
1.34 - t = line.strip(" \r\n").split("\t")
1.35 + line = line.strip(" \r\n")
1.36 + if tab_separated:
1.37 + t = line.split("\t")
1.38 + else:
1.39 + t = parse_line(line)
1.40 if empty_defaults:
1.41 t = self._set_defaults(t, empty_defaults)
1.42 l.append(tuple(t))
1.43 @@ -73,7 +82,7 @@
1.44 finally:
1.45 f.close()
1.46
1.47 - def _get_table_atomic(self, user, filename, empty_defaults=None):
1.48 + def _get_table_atomic(self, user, filename, empty_defaults=None, tab_separated=True):
1.49
1.50 """
1.51 From the file for the given 'user' having the given 'filename', return
1.52 @@ -82,11 +91,15 @@
1.53 The 'empty_defaults' is a list of (index, value) tuples indicating the
1.54 default value where a column either does not exist or provides an empty
1.55 value.
1.56 +
1.57 + If 'tab_separated' is specified and is a false value, line parsing using
1.58 + the imiptools.text.parse_line function will be performed instead of
1.59 + splitting each line of the file using tab characters as separators.
1.60 """
1.61
1.62 self.acquire_lock(user)
1.63 try:
1.64 - return self._get_table(user, filename, empty_defaults)
1.65 + return self._get_table(user, filename, empty_defaults, tab_separated)
1.66 finally:
1.67 self.release_lock(user)
1.68
1.69 @@ -958,7 +971,7 @@
1.70 if not filename or not isfile(filename):
1.71 return {}
1.72
1.73 - return dict(self._get_table_atomic(quota, filename))
1.74 + return dict(self._get_table_atomic(quota, filename, tab_separated=False))
1.75
1.76 def get_limits(self, quota):
1.77
1.78 @@ -971,7 +984,7 @@
1.79 if not filename or not isfile(filename):
1.80 return None
1.81
1.82 - return dict(self._get_table_atomic(quota, filename))
1.83 + return dict(self._get_table_atomic(quota, filename, tab_separated=False))
1.84
1.85 # Free/busy period access.
1.86