1.1 --- a/imiptools/stores/file.py Thu Apr 21 23:17:35 2016 +0200
1.2 +++ b/imiptools/stores/file.py Thu Apr 21 23:20:57 2016 +0200
1.3 @@ -232,25 +232,19 @@
1.4
1.5 filename = self.get_object_in_store(user, "objects")
1.6 if not filename or not isdir(filename):
1.7 - return None
1.8 + return []
1.9
1.10 return [name for name in listdir(filename) if isfile(join(filename, name))]
1.11
1.12 - def get_event_filename(self, user, uid, recurrenceid=None, dirname=None, username=None):
1.13 + def get_cancelled_events(self, user):
1.14
1.15 - """
1.16 - Get the filename providing the event for the given 'user' with the given
1.17 - 'uid'. If the optional 'recurrenceid' is specified, a specific instance
1.18 - or occurrence of an event is returned.
1.19 + "Return a list of event identifiers for cancelled events."
1.20
1.21 - Where 'dirname' is specified, the given directory name is used as the
1.22 - base of the location within which any filename will reside.
1.23 - """
1.24 + filename = self.get_object_in_store(user, "cancellations", "objects")
1.25 + if not filename or not isdir(filename):
1.26 + return []
1.27
1.28 - if recurrenceid:
1.29 - return self.get_recurrence_filename(user, uid, recurrenceid, dirname, username)
1.30 - else:
1.31 - return self.get_complete_event_filename(user, uid, dirname, username)
1.32 + return [name for name in listdir(filename) if isfile(join(filename, name))]
1.33
1.34 def get_event(self, user, uid, recurrenceid=None, dirname=None):
1.35
1.36 @@ -266,21 +260,6 @@
1.37
1.38 return filename and self._get_object(user, filename)
1.39
1.40 - def get_complete_event_filename(self, user, uid, dirname=None, username=None):
1.41 -
1.42 - """
1.43 - Get the filename providing the event for the given 'user' with the given
1.44 - 'uid'.
1.45 -
1.46 - Where 'dirname' is specified, the given directory name is used as the
1.47 - base of the location within which any filename will reside.
1.48 -
1.49 - Where 'username' is specified, the event details will reside in a file
1.50 - bearing that name within a directory having 'uid' as its name.
1.51 - """
1.52 -
1.53 - return self.get_object_in_store(user, dirname, "objects", uid, username)
1.54 -
1.55 def get_complete_event(self, user, uid):
1.56
1.57 "Get the event for the given 'user' with the given 'uid'."
1.58 @@ -346,21 +325,6 @@
1.59
1.60 return [name for name in listdir(filename) if isfile(join(filename, name))]
1.61
1.62 - def get_recurrence_filename(self, user, uid, recurrenceid, dirname=None, username=None):
1.63 -
1.64 - """
1.65 - For the event of the given 'user' with the given 'uid', return the
1.66 - filename providing the recurrence with the given 'recurrenceid'.
1.67 -
1.68 - Where 'dirname' is specified, the given directory name is used as the
1.69 - base of the location within which any filename will reside.
1.70 -
1.71 - Where 'username' is specified, the event details will reside in a file
1.72 - bearing that name within a directory having 'uid' as its name.
1.73 - """
1.74 -
1.75 - return self.get_object_in_store(user, dirname, "recurrences", uid, recurrenceid, username)
1.76 -
1.77 def get_recurrence(self, user, uid, recurrenceid):
1.78
1.79 """
1.80 @@ -410,6 +374,54 @@
1.81
1.82 return True
1.83
1.84 + # Event filename computation.
1.85 +
1.86 + def get_event_filename(self, user, uid, recurrenceid=None, dirname=None, username=None):
1.87 +
1.88 + """
1.89 + Get the filename providing the event for the given 'user' with the given
1.90 + 'uid'. If the optional 'recurrenceid' is specified, a specific instance
1.91 + or occurrence of an event is returned.
1.92 +
1.93 + Where 'dirname' is specified, the given directory name is used as the
1.94 + base of the location within which any filename will reside.
1.95 + """
1.96 +
1.97 + if recurrenceid:
1.98 + return self.get_recurrence_filename(user, uid, recurrenceid, dirname, username)
1.99 + else:
1.100 + return self.get_complete_event_filename(user, uid, dirname, username)
1.101 +
1.102 + def get_recurrence_filename(self, user, uid, recurrenceid, dirname=None, username=None):
1.103 +
1.104 + """
1.105 + For the event of the given 'user' with the given 'uid', return the
1.106 + filename providing the recurrence with the given 'recurrenceid'.
1.107 +
1.108 + Where 'dirname' is specified, the given directory name is used as the
1.109 + base of the location within which any filename will reside.
1.110 +
1.111 + Where 'username' is specified, the event details will reside in a file
1.112 + bearing that name within a directory having 'uid' as its name.
1.113 + """
1.114 +
1.115 + return self.get_object_in_store(user, dirname, "recurrences", uid, recurrenceid, username)
1.116 +
1.117 + def get_complete_event_filename(self, user, uid, dirname=None, username=None):
1.118 +
1.119 + """
1.120 + Get the filename providing the event for the given 'user' with the given
1.121 + 'uid'.
1.122 +
1.123 + Where 'dirname' is specified, the given directory name is used as the
1.124 + base of the location within which any filename will reside.
1.125 +
1.126 + Where 'username' is specified, the event details will reside in a file
1.127 + bearing that name within a directory having 'uid' as its name.
1.128 + """
1.129 +
1.130 + return self.get_object_in_store(user, dirname, "objects", uid, username)
1.131 +
1.132 # Free/busy period providers, upon extension of the free/busy records.
1.133
1.134 def _get_freebusy_providers(self, user):
1.135 @@ -502,6 +514,20 @@
1.136 map(lambda fb: fb.as_tuple(strings_only=True), freebusy.periods))
1.137 return True
1.138
1.139 + def get_freebusy_others(self, user):
1.140 +
1.141 + """
1.142 + For the given 'user', return a list of other users for whom free/busy
1.143 + information is retained.
1.144 + """
1.145 +
1.146 + filename = self.get_object_in_store(user, "freebusy-other")
1.147 +
1.148 + if not filename or not isdir(filename):
1.149 + return []
1.150 +
1.151 + return listdir(filename)
1.152 +
1.153 # Tentative free/busy periods related to countering.
1.154
1.155 def get_freebusy_offers(self, user, mutable=False):
1.156 @@ -538,7 +564,7 @@
1.157
1.158 filename = self.get_object_in_store(user, queue)
1.159 if not filename or not isfile(filename):
1.160 - return None
1.161 + return []
1.162
1.163 return self._get_table_atomic(user, filename, [(1, None), (2, None)])
1.164
1.165 @@ -609,7 +635,7 @@
1.166
1.167 filename = self.get_event_filename(user, uid, recurrenceid, "counters")
1.168 if not filename or not isdir(filename):
1.169 - return False
1.170 + return []
1.171
1.172 return [name for name in listdir(filename) if isfile(join(filename, name))]
1.173
1.174 @@ -622,7 +648,7 @@
1.175
1.176 filename = self.get_event_filename(user, uid, recurrenceid, "counters", other)
1.177 if not filename or not isfile(filename):
1.178 - return False
1.179 + return None
1.180
1.181 return self._get_object(user, filename)
1.182
1.183 @@ -797,6 +823,22 @@
1.184
1.185 return dict(self._get_table_atomic(quota, filename, tab_separated=False))
1.186
1.187 + def set_group(self, quota, store_user, user_group):
1.188 +
1.189 + """
1.190 + For the given 'quota', set a mapping from 'store_user' to 'user_group'.
1.191 + """
1.192 +
1.193 + filename = self.get_object_in_store(quota, "groups")
1.194 + if not filename:
1.195 + return False
1.196 +
1.197 + groups = self.get_groups(quota) or {}
1.198 + groups[store_user] = user_group
1.199 +
1.200 + self._set_table_atomic(quota, filename, groups.items())
1.201 + return True
1.202 +
1.203 def get_limits(self, quota):
1.204
1.205 """
1.206 @@ -806,7 +848,7 @@
1.207
1.208 filename = self.get_object_in_store(quota, "limits")
1.209 if not filename or not isfile(filename):
1.210 - return None
1.211 + return {}
1.212
1.213 return dict(self._get_table_atomic(quota, filename, tab_separated=False))
1.214
1.215 @@ -819,7 +861,7 @@
1.216
1.217 filename = self.get_object_in_store(quota, "limits")
1.218 if not filename:
1.219 - return None
1.220 + return False
1.221
1.222 limits = self.get_limits(quota) or {}
1.223 limits[group] = limit
1.224 @@ -829,6 +871,19 @@
1.225
1.226 # Free/busy period access for users within quota groups.
1.227
1.228 + def get_freebusy_users(self, quota):
1.229 +
1.230 + """
1.231 + Return a list of users whose free/busy details are retained for the
1.232 + given 'quota'.
1.233 + """
1.234 +
1.235 + filename = self.get_object_in_store(quota, "freebusy")
1.236 + if not filename or not isdir(filename):
1.237 + return []
1.238 +
1.239 + return listdir(filename)
1.240 +
1.241 def get_freebusy(self, quota, user, mutable=False):
1.242
1.243 "Get free/busy details for the given 'quota' and 'user'."