1.1 --- a/imiptools/__init__.py Tue Oct 17 17:43:42 2017 +0200
1.2 +++ b/imiptools/__init__.py Tue Oct 17 22:58:26 2017 +0200
1.3 @@ -62,13 +62,22 @@
1.4 self.debug = False
1.5
1.6 def get_store(self):
1.7 - return get_store(self.store_type, self.store_dir)
1.8 +
1.9 + "Return any configured store or None if not explicitly configured."
1.10 +
1.11 + return self.store_dir and get_store(self.store_type, self.store_dir) or None
1.12
1.13 def get_publisher(self):
1.14 - return get_publisher(self.publishing_dir)
1.15 +
1.16 + "Return any configured publisher or None if not explicitly configured."
1.17 +
1.18 + return self.publishing_dir and get_publisher(self.publishing_dir) or None
1.19
1.20 def get_journal(self):
1.21 - return get_journal(self.store_type, self.journal_dir)
1.22 +
1.23 + "Return any configured journal or None if not explicitly configured."
1.24 +
1.25 + return self.journal_dir and get_journal(self.store_type, self.journal_dir) or None
1.26
1.27 def process(self, f, original_recipients):
1.28
2.1 --- a/imiptools/client.py Tue Oct 17 17:43:42 2017 +0200
2.2 +++ b/imiptools/client.py Tue Oct 17 22:58:26 2017 +0200
2.3 @@ -56,14 +56,16 @@
2.4
2.5 self.user = user
2.6 self.messenger = messenger
2.7 - self.store = store or get_store(settings["STORE_TYPE"], settings["STORE_DIR"])
2.8 - self.journal = journal or get_journal(settings["STORE_TYPE"], settings["JOURNAL_DIR"])
2.9 +
2.10 + # The store is mandatory and will be initialised using defaults if not
2.11 + # provided.
2.12
2.13 - try:
2.14 - self.publisher = publisher or get_publisher(settings["PUBLISH_DIR"])
2.15 - except OSError:
2.16 - self.publisher = None
2.17 + self.store = store or get_store()
2.18
2.19 + # Journal and publisher objects are optional.
2.20 +
2.21 + self.journal = journal
2.22 + self.publisher = publisher
2.23 self.preferences_dir = preferences_dir
2.24 self.preferences = None
2.25
3.1 --- a/imiptools/handlers/scheduling/quota.py Tue Oct 17 17:43:42 2017 +0200
3.2 +++ b/imiptools/handlers/scheduling/quota.py Tue Oct 17 22:58:26 2017 +0200
3.3 @@ -36,11 +36,14 @@
3.4
3.5 _ = handler.get_translator()
3.6
3.7 - quota, group = _get_quota_and_group(handler, args)
3.8 -
3.9 # Obtain the journal entries and check the balance.
3.10
3.11 journal = handler.get_journal()
3.12 + if not journal:
3.13 + return "DECLINED", _("You have no quota allocation for the recipient.")
3.14 +
3.15 + quota, group = _get_quota_and_group(handler, args)
3.16 +
3.17 entries = journal.get_entries(quota, group)
3.18 limits = journal.get_limits(quota)
3.19
3.20 @@ -79,6 +82,9 @@
3.21 applicable quota.
3.22 """
3.23
3.24 + if not handler.get_journal():
3.25 + return
3.26 +
3.27 quota, group = _get_quota_and_group(handler, args)
3.28 _add_to_quota(handler, quota, group, handler.user, False)
3.29
3.30 @@ -89,6 +95,9 @@
3.31 applicable quota.
3.32 """
3.33
3.34 + if not handler.get_journal():
3.35 + return
3.36 +
3.37 quota, group = _get_quota_and_group(handler, args)
3.38 _remove_from_quota(handler, quota, group, handler.user)
3.39
3.40 @@ -96,8 +105,11 @@
3.41
3.42 "Update a stored version of the current object of the given 'handler'."
3.43
3.44 + journal = handler.get_journal()
3.45 + if not journal:
3.46 + return
3.47 +
3.48 quota, group = _get_quota_and_group(handler, args)
3.49 - journal = handler.get_journal()
3.50
3.51 # Where an existing version of the object exists, merge the recipient's
3.52 # attendance information.
3.53 @@ -120,8 +132,11 @@
3.54
3.55 "Remove a stored version of the current object of the given 'handler'."
3.56
3.57 + journal = handler.get_journal()
3.58 + if not journal:
3.59 + return
3.60 +
3.61 quota, group = _get_quota_and_group(handler, args)
3.62 - journal = handler.get_journal()
3.63
3.64 # Where an existing version of the object exists, remove the recipient's
3.65 # attendance information.
3.66 @@ -160,6 +175,9 @@
3.67 identity or group involved.
3.68 """
3.69
3.70 + journal = handler.get_journal()
3.71 + assert journal
3.72 +
3.73 quota = args and args[0] or handler.user
3.74
3.75 # Obtain the identity to whom the quota will apply.
3.76 @@ -168,7 +186,6 @@
3.77
3.78 # Obtain any user group to which the quota will apply instead.
3.79
3.80 - journal = handler.get_journal()
3.81 groups = journal.get_groups(quota)
3.82
3.83 return quota, groups.get(organiser) or groups.get("*") or organiser
3.84 @@ -230,6 +247,8 @@
3.85 """
3.86
3.87 journal = handler.get_journal()
3.88 + assert journal
3.89 +
3.90 freebusy = journal.get_entries_for_update(quota, user)
3.91 handler.update_freebusy(freebusy, participant, is_organiser)
3.92
3.93 @@ -253,6 +272,8 @@
3.94 """
3.95
3.96 journal = handler.get_journal()
3.97 + assert journal
3.98 +
3.99 freebusy = journal.get_entries_for_update(quota, user)
3.100
3.101 # Remove only the entries associated with this recipient.
3.102 @@ -276,6 +297,9 @@
3.103 nor are the quotas themselves.
3.104 """
3.105
3.106 + if not handler.get_journal():
3.107 + return standard_responses(handler, "DECLINED")
3.108 +
3.109 quota, organiser = _get_quota_and_identity(handler, args)
3.110
3.111 # Check the event periods against the quota's consolidated record of the
3.112 @@ -294,6 +318,9 @@
3.113 free/busy resource.
3.114 """
3.115
3.116 + if not handler.get_journal():
3.117 + return
3.118 +
3.119 quota, organiser = _get_quota_and_identity(handler, args)
3.120 _add_to_quota(handler, quota, organiser, organiser, True)
3.121
3.122 @@ -304,6 +331,9 @@
3.123 free/busy resource.
3.124 """
3.125
3.126 + if not handler.get_journal():
3.127 + return
3.128 +
3.129 quota, organiser = _get_quota_and_identity(handler, args)
3.130 _remove_from_quota(handler, quota, organiser, organiser)
3.131
3.132 @@ -315,6 +345,8 @@
3.133 identity involved.
3.134 """
3.135
3.136 + assert handler.get_journal()
3.137 +
3.138 quota = args and args[0] or handler.user
3.139
3.140 # Obtain the identity for whom the scheduling will apply.
3.141 @@ -341,6 +373,12 @@
3.142 if response == "DECLINED":
3.143 return response, description
3.144
3.145 + # Obtain the journal. Any absent journal should have caused a DECLINED
3.146 + # response, so this is merely to document the dependency.
3.147 +
3.148 + journal = handler.get_journal()
3.149 + assert journal
3.150 +
3.151 # Obtain the quota and organiser group details to evaluate delegation.
3.152
3.153 quota, group = _get_quota_and_group(handler, args)
3.154 @@ -359,7 +397,7 @@
3.155 # Obtain the delegate pool for the quota.
3.156
3.157 else:
3.158 - delegates = handler.get_journal().get_delegates(quota)
3.159 + delegates = journal.get_delegates(quota)
3.160
3.161 # Obtain the remaining delegates not already involved in the event.
3.162
3.163 @@ -369,7 +407,7 @@
3.164 # Get the quota's schedule for the requested periods and identify
3.165 # unavailable delegates.
3.166
3.167 - entries = handler.get_journal().get_entries(quota, group)
3.168 + entries = journal.get_entries(quota, group)
3.169 conflicts = get_scheduling_conflicts(handler, entries, delegates, attendee=True)
3.170
3.171 # Get the delegates in order of increasing unavailability (or decreasing
3.172 @@ -417,13 +455,17 @@
3.173
3.174 "Using the 'handler' and 'args', lock the journal for the quota."
3.175
3.176 - handler.get_journal().acquire_lock(_get_quota(handler, args))
3.177 + journal = handler.get_journal()
3.178 + if journal:
3.179 + journal.acquire_lock(_get_quota(handler, args))
3.180
3.181 def unlock_journal(handler, args):
3.182
3.183 "Using the 'handler' and 'args', unlock the journal for the quota."
3.184
3.185 - handler.get_journal().release_lock(_get_quota(handler, args))
3.186 + journal = handler.get_journal()
3.187 + if journal:
3.188 + journal.release_lock(_get_quota(handler, args))
3.189
3.190 def _get_quota(handler, args):
3.191
4.1 --- a/imiptools/stores/__init__.py Tue Oct 17 17:43:42 2017 +0200
4.2 +++ b/imiptools/stores/__init__.py Tue Oct 17 22:58:26 2017 +0200
4.3 @@ -19,38 +19,39 @@
4.4 this program. If not, see <http://www.gnu.org/licenses/>.
4.5 """
4.6
4.7 +from imiptools.config import settings
4.8 from imiptools.stores.manifest import stores
4.9
4.10 # Access functions.
4.11
4.12 -def get_store(store_type, store_dir):
4.13 +def get_store(store_type=None, store_dir=None):
4.14
4.15 """
4.16 - Return a store for the given 'store_type' and 'store_dir'. If 'store_dir'
4.17 - is given as a null or false value then the configured default is used.
4.18 + Return a store object for the given 'store_type' and 'store_dir', using
4.19 + configuration defaults where the parameters are given as None.
4.20 """
4.21
4.22 - return stores[store_type].Store(store_dir)
4.23 + return stores[store_type or settings["STORE_TYPE"]].Store(
4.24 + store_dir or settings["STORE_DIR"])
4.25
4.26 -def get_publisher(publishing_dir):
4.27 +def get_publisher(publishing_dir=None):
4.28
4.29 """
4.30 - Return a publishing resource employing 'publishing_dir'. If the specified
4.31 - directory is given as a null or false value, None is returned. Thus, all
4.32 - free/busy publishing can be disabled by changing the configuration to use
4.33 - None as the directory.
4.34 + Return a publisher object for the given 'publishing_dir', using
4.35 + configuration defaults where the parameter is given as None.
4.36 """
4.37
4.38 - return publishing_dir and stores["file"].Publisher(publishing_dir) or None
4.39 + return stores["file"].Publisher(
4.40 + publishing_dir or settings["PUBLISHING_DIR"])
4.41
4.42 -def get_journal(store_type, journal_dir):
4.43 +def get_journal(store_type=None, journal_dir=None):
4.44
4.45 """
4.46 - Return a journal for the given 'store_type' and 'journal_dir'. If
4.47 - 'journal_dir' is given as a null or false value then the configured default
4.48 - is used.
4.49 + Return a journal object for the given 'store_type' and 'journal_dir', using
4.50 + configuration defaults where the parameters are given as None.
4.51 """
4.52
4.53 - return stores[store_type].Journal(journal_dir)
4.54 + return stores[store_type or settings["STORE_TYPE"]].Journal(
4.55 + journal_dir or settings["JOURNAL_DIR"])
4.56
4.57 # vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/tests/list_table.py Tue Oct 17 17:43:42 2017 +0200
5.2 +++ b/tests/list_table.py Tue Oct 17 22:58:26 2017 +0200
5.3 @@ -60,6 +60,9 @@
5.4
5.5 if table == "entries":
5.6 group = args[0]
5.7 + if not journal:
5.8 + print >>sys.stderr, "Journal not present."
5.9 + sys.exit(1)
5.10 data = journal.get_entries(user, group)
5.11 show_periods(data)
5.12
5.13 @@ -87,6 +90,9 @@
5.14 show_tuples(data)
5.15
5.16 elif table == "journal_freebusy_providers":
5.17 + if not journal:
5.18 + print >>sys.stderr, "Journal not present."
5.19 + sys.exit(1)
5.20 data = journal.get_freebusy_providers(user)
5.21 show_tuples(data)
5.22
5.23 @@ -105,6 +111,9 @@
5.24
5.25 elif table == "journal_object":
5.26 uid = args[0]
5.27 + if not journal:
5.28 + print >>sys.stderr, "Journal not present."
5.29 + sys.exit(1)
5.30 obj = journal.get_event(user, uid)
5.31 show_object(obj)
5.32
6.1 --- a/tools/make_freebusy.py Tue Oct 17 17:43:42 2017 +0200
6.2 +++ b/tools/make_freebusy.py Tue Oct 17 22:58:26 2017 +0200
6.3 @@ -278,9 +278,9 @@
6.4
6.5 # Obtain store-related objects or delegate this to the Client initialiser.
6.6
6.7 - store = get_store(store_type, store_dir)
6.8 - publisher = get_publisher(publishing_dir)
6.9 - journal = get_journal(store_type, journal_dir)
6.10 + store = store_dir and get_store(store_type, store_dir) or None
6.11 + publisher = publishing_dir and get_publisher(publishing_dir) or None
6.12 + journal = journal_dir and get_journal(store_type, journal_dir) or None
6.13
6.14 # Determine which kind of object will be accessed.
6.15
7.1 --- a/tools/set_delegates.py Tue Oct 17 17:43:42 2017 +0200
7.2 +++ b/tools/set_delegates.py Tue Oct 17 22:58:26 2017 +0200
7.3 @@ -82,6 +82,10 @@
7.4 # Obtain store-related objects.
7.5
7.6 journal = get_journal(store_type, journal_dir)
7.7 + if not journal:
7.8 + print >>sys.stderr, "Journal not present."
7.9 + sys.exit(1)
7.10 +
7.11 f = getreader("utf-8")(sys.stdin)
7.12 delegates = get_table_from_stream(f, tab_separated=False)
7.13 journal.set_delegates(quota, [value for (value,) in delegates])
8.1 --- a/tools/set_quota_groups.py Tue Oct 17 17:43:42 2017 +0200
8.2 +++ b/tools/set_quota_groups.py Tue Oct 17 22:58:26 2017 +0200
8.3 @@ -93,6 +93,10 @@
8.4 # Obtain store-related objects.
8.5
8.6 journal = get_journal(store_type, journal_dir)
8.7 + if not journal:
8.8 + print >>sys.stderr, "Journal not present."
8.9 + sys.exit(1)
8.10 +
8.11 f = getreader("utf-8")(sys.stdin)
8.12 groups = dict(get_table_from_stream(f, tab_separated=False))
8.13 journal.set_groups(quota, groups)
9.1 --- a/tools/set_quota_limits.py Tue Oct 17 17:43:42 2017 +0200
9.2 +++ b/tools/set_quota_limits.py Tue Oct 17 22:58:26 2017 +0200
9.3 @@ -93,6 +93,10 @@
9.4 # Obtain store-related objects.
9.5
9.6 journal = get_journal(store_type, journal_dir)
9.7 + if not journal:
9.8 + print >>sys.stderr, "Journal not present."
9.9 + sys.exit(1)
9.10 +
9.11 f = getreader("utf-8")(sys.stdin)
9.12 limits = dict(get_table_from_stream(f, tab_separated=False))
9.13 journal.set_limits(quota, limits)
10.1 --- a/tools/update_quotas.py Tue Oct 17 17:43:42 2017 +0200
10.2 +++ b/tools/update_quotas.py Tue Oct 17 22:58:26 2017 +0200
10.3 @@ -173,6 +173,9 @@
10.4 # Obtain store-related objects.
10.5
10.6 journal = get_journal(store_type, journal_dir)
10.7 + if not journal:
10.8 + print >>sys.stderr, "Journal not present."
10.9 + sys.exit(1)
10.10
10.11 # Obtain a list of users for processing.
10.12