1.1 --- a/imiptools/stores/file.py Thu May 12 23:05:48 2016 +0200
1.2 +++ b/imiptools/stores/file.py Thu May 12 23:15:18 2016 +0200
1.3 @@ -796,13 +796,36 @@
1.4
1.5 def get_quota_users(self, quota):
1.6
1.7 - "Return a list of quota users."
1.8 + "Return a list of quota users for 'quota'."
1.9
1.10 filename = self.get_object_in_store(quota, "journal")
1.11 if not filename or not isdir(filename):
1.12 return []
1.13
1.14 - return listdir(filename)
1.15 + return list(set(self.get_delegates(quota)).union(listdir(filename)))
1.16 +
1.17 + # Delegate information for the quota.
1.18 +
1.19 + def get_delegates(self, quota):
1.20 +
1.21 + "Return a list of delegates for 'quota'."
1.22 +
1.23 + filename = self.get_object_in_store(quota, "delegates")
1.24 + if not filename or not isfile(filename):
1.25 + return []
1.26 +
1.27 + return [value for (value,) in self._get_table_atomic(quota, filename)]
1.28 +
1.29 + def set_delegates(self, quota, delegates):
1.30 +
1.31 + "For the given 'quota', set the list of 'delegates'."
1.32 +
1.33 + filename = self.get_object_in_store(quota, "delegates")
1.34 + if not filename:
1.35 + return False
1.36 +
1.37 + self._set_table_atomic(quota, filename, [(value,) for value in delegates])
1.38 + return True
1.39
1.40 # Groups of users sharing quotas.
1.41
1.42 @@ -816,19 +839,14 @@
1.43
1.44 return dict(self._get_table_atomic(quota, filename, tab_separated=False))
1.45
1.46 - def set_group(self, quota, store_user, user_group):
1.47 + def set_groups(self, quota, groups):
1.48
1.49 - """
1.50 - For the given 'quota', set a mapping from 'store_user' to 'user_group'.
1.51 - """
1.52 + "For the given 'quota', set 'groups' mapping users to groups."
1.53
1.54 filename = self.get_object_in_store(quota, "groups")
1.55 if not filename:
1.56 return False
1.57
1.58 - groups = self.get_groups(quota) or {}
1.59 - groups[store_user] = user_group
1.60 -
1.61 self._set_table_atomic(quota, filename, groups.items())
1.62 return True
1.63
1.64 @@ -845,20 +863,17 @@
1.65
1.66 return dict(self._get_table_atomic(quota, filename, tab_separated=False))
1.67
1.68 - def set_limit(self, quota, group, limit):
1.69 + def set_limits(self, quota, limits):
1.70
1.71 """
1.72 - For the given 'quota', set for a user 'group' the given 'limit' on
1.73 - resource usage.
1.74 + For the given 'quota', set the given 'limits' on resource usage mapping
1.75 + groups to limits.
1.76 """
1.77
1.78 filename = self.get_object_in_store(quota, "limits")
1.79 if not filename:
1.80 return False
1.81
1.82 - limits = self.get_limits(quota) or {}
1.83 - limits[group] = limit
1.84 -
1.85 self._set_table_atomic(quota, filename, limits.items())
1.86 return True
1.87