# HG changeset patch # User Paul Boddie # Date 1508273906 -7200 # Node ID f5b485cc5a930f6b8595d92d399286b1a6586a5c # Parent e811fc71e425f2f8d3be127572254ab3e2c31a47# Parent 8d0357f49f6d82c2dc0995687bece6a096c118d4 Merged changes from the default branch. diff -r e811fc71e425 -r f5b485cc5a93 imiptools/__init__.py --- a/imiptools/__init__.py Tue Oct 17 17:43:42 2017 +0200 +++ b/imiptools/__init__.py Tue Oct 17 22:58:26 2017 +0200 @@ -62,13 +62,22 @@ self.debug = False def get_store(self): - return get_store(self.store_type, self.store_dir) + + "Return any configured store or None if not explicitly configured." + + return self.store_dir and get_store(self.store_type, self.store_dir) or None def get_publisher(self): - return get_publisher(self.publishing_dir) + + "Return any configured publisher or None if not explicitly configured." + + return self.publishing_dir and get_publisher(self.publishing_dir) or None def get_journal(self): - return get_journal(self.store_type, self.journal_dir) + + "Return any configured journal or None if not explicitly configured." + + return self.journal_dir and get_journal(self.store_type, self.journal_dir) or None def process(self, f, original_recipients): diff -r e811fc71e425 -r f5b485cc5a93 imiptools/client.py --- a/imiptools/client.py Tue Oct 17 17:43:42 2017 +0200 +++ b/imiptools/client.py Tue Oct 17 22:58:26 2017 +0200 @@ -56,14 +56,16 @@ self.user = user self.messenger = messenger - self.store = store or get_store(settings["STORE_TYPE"], settings["STORE_DIR"]) - self.journal = journal or get_journal(settings["STORE_TYPE"], settings["JOURNAL_DIR"]) + + # The store is mandatory and will be initialised using defaults if not + # provided. - try: - self.publisher = publisher or get_publisher(settings["PUBLISH_DIR"]) - except OSError: - self.publisher = None + self.store = store or get_store() + # Journal and publisher objects are optional. + + self.journal = journal + self.publisher = publisher self.preferences_dir = preferences_dir self.preferences = None diff -r e811fc71e425 -r f5b485cc5a93 imiptools/handlers/scheduling/quota.py --- a/imiptools/handlers/scheduling/quota.py Tue Oct 17 17:43:42 2017 +0200 +++ b/imiptools/handlers/scheduling/quota.py Tue Oct 17 22:58:26 2017 +0200 @@ -36,11 +36,14 @@ _ = handler.get_translator() - quota, group = _get_quota_and_group(handler, args) - # Obtain the journal entries and check the balance. journal = handler.get_journal() + if not journal: + return "DECLINED", _("You have no quota allocation for the recipient.") + + quota, group = _get_quota_and_group(handler, args) + entries = journal.get_entries(quota, group) limits = journal.get_limits(quota) @@ -79,6 +82,9 @@ applicable quota. """ + if not handler.get_journal(): + return + quota, group = _get_quota_and_group(handler, args) _add_to_quota(handler, quota, group, handler.user, False) @@ -89,6 +95,9 @@ applicable quota. """ + if not handler.get_journal(): + return + quota, group = _get_quota_and_group(handler, args) _remove_from_quota(handler, quota, group, handler.user) @@ -96,8 +105,11 @@ "Update a stored version of the current object of the given 'handler'." + journal = handler.get_journal() + if not journal: + return + quota, group = _get_quota_and_group(handler, args) - journal = handler.get_journal() # Where an existing version of the object exists, merge the recipient's # attendance information. @@ -120,8 +132,11 @@ "Remove a stored version of the current object of the given 'handler'." + journal = handler.get_journal() + if not journal: + return + quota, group = _get_quota_and_group(handler, args) - journal = handler.get_journal() # Where an existing version of the object exists, remove the recipient's # attendance information. @@ -160,6 +175,9 @@ identity or group involved. """ + journal = handler.get_journal() + assert journal + quota = args and args[0] or handler.user # Obtain the identity to whom the quota will apply. @@ -168,7 +186,6 @@ # Obtain any user group to which the quota will apply instead. - journal = handler.get_journal() groups = journal.get_groups(quota) return quota, groups.get(organiser) or groups.get("*") or organiser @@ -230,6 +247,8 @@ """ journal = handler.get_journal() + assert journal + freebusy = journal.get_entries_for_update(quota, user) handler.update_freebusy(freebusy, participant, is_organiser) @@ -253,6 +272,8 @@ """ journal = handler.get_journal() + assert journal + freebusy = journal.get_entries_for_update(quota, user) # Remove only the entries associated with this recipient. @@ -276,6 +297,9 @@ nor are the quotas themselves. """ + if not handler.get_journal(): + return standard_responses(handler, "DECLINED") + quota, organiser = _get_quota_and_identity(handler, args) # Check the event periods against the quota's consolidated record of the @@ -294,6 +318,9 @@ free/busy resource. """ + if not handler.get_journal(): + return + quota, organiser = _get_quota_and_identity(handler, args) _add_to_quota(handler, quota, organiser, organiser, True) @@ -304,6 +331,9 @@ free/busy resource. """ + if not handler.get_journal(): + return + quota, organiser = _get_quota_and_identity(handler, args) _remove_from_quota(handler, quota, organiser, organiser) @@ -315,6 +345,8 @@ identity involved. """ + assert handler.get_journal() + quota = args and args[0] or handler.user # Obtain the identity for whom the scheduling will apply. @@ -341,6 +373,12 @@ if response == "DECLINED": return response, description + # Obtain the journal. Any absent journal should have caused a DECLINED + # response, so this is merely to document the dependency. + + journal = handler.get_journal() + assert journal + # Obtain the quota and organiser group details to evaluate delegation. quota, group = _get_quota_and_group(handler, args) @@ -359,7 +397,7 @@ # Obtain the delegate pool for the quota. else: - delegates = handler.get_journal().get_delegates(quota) + delegates = journal.get_delegates(quota) # Obtain the remaining delegates not already involved in the event. @@ -369,7 +407,7 @@ # Get the quota's schedule for the requested periods and identify # unavailable delegates. - entries = handler.get_journal().get_entries(quota, group) + entries = journal.get_entries(quota, group) conflicts = get_scheduling_conflicts(handler, entries, delegates, attendee=True) # Get the delegates in order of increasing unavailability (or decreasing @@ -417,13 +455,17 @@ "Using the 'handler' and 'args', lock the journal for the quota." - handler.get_journal().acquire_lock(_get_quota(handler, args)) + journal = handler.get_journal() + if journal: + journal.acquire_lock(_get_quota(handler, args)) def unlock_journal(handler, args): "Using the 'handler' and 'args', unlock the journal for the quota." - handler.get_journal().release_lock(_get_quota(handler, args)) + journal = handler.get_journal() + if journal: + journal.release_lock(_get_quota(handler, args)) def _get_quota(handler, args): diff -r e811fc71e425 -r f5b485cc5a93 imiptools/stores/__init__.py --- a/imiptools/stores/__init__.py Tue Oct 17 17:43:42 2017 +0200 +++ b/imiptools/stores/__init__.py Tue Oct 17 22:58:26 2017 +0200 @@ -19,38 +19,39 @@ this program. If not, see . """ +from imiptools.config import settings from imiptools.stores.manifest import stores # Access functions. -def get_store(store_type, store_dir): +def get_store(store_type=None, store_dir=None): """ - Return a store for the given 'store_type' and 'store_dir'. If 'store_dir' - is given as a null or false value then the configured default is used. + Return a store object for the given 'store_type' and 'store_dir', using + configuration defaults where the parameters are given as None. """ - return stores[store_type].Store(store_dir) + return stores[store_type or settings["STORE_TYPE"]].Store( + store_dir or settings["STORE_DIR"]) -def get_publisher(publishing_dir): +def get_publisher(publishing_dir=None): """ - Return a publishing resource employing 'publishing_dir'. If the specified - directory is given as a null or false value, None is returned. Thus, all - free/busy publishing can be disabled by changing the configuration to use - None as the directory. + Return a publisher object for the given 'publishing_dir', using + configuration defaults where the parameter is given as None. """ - return publishing_dir and stores["file"].Publisher(publishing_dir) or None + return stores["file"].Publisher( + publishing_dir or settings["PUBLISHING_DIR"]) -def get_journal(store_type, journal_dir): +def get_journal(store_type=None, journal_dir=None): """ - Return a journal for the given 'store_type' and 'journal_dir'. If - 'journal_dir' is given as a null or false value then the configured default - is used. + Return a journal object for the given 'store_type' and 'journal_dir', using + configuration defaults where the parameters are given as None. """ - return stores[store_type].Journal(journal_dir) + return stores[store_type or settings["STORE_TYPE"]].Journal( + journal_dir or settings["JOURNAL_DIR"]) # vim: tabstop=4 expandtab shiftwidth=4 diff -r e811fc71e425 -r f5b485cc5a93 tests/list_table.py --- a/tests/list_table.py Tue Oct 17 17:43:42 2017 +0200 +++ b/tests/list_table.py Tue Oct 17 22:58:26 2017 +0200 @@ -60,6 +60,9 @@ if table == "entries": group = args[0] + if not journal: + print >>sys.stderr, "Journal not present." + sys.exit(1) data = journal.get_entries(user, group) show_periods(data) @@ -87,6 +90,9 @@ show_tuples(data) elif table == "journal_freebusy_providers": + if not journal: + print >>sys.stderr, "Journal not present." + sys.exit(1) data = journal.get_freebusy_providers(user) show_tuples(data) @@ -105,6 +111,9 @@ elif table == "journal_object": uid = args[0] + if not journal: + print >>sys.stderr, "Journal not present." + sys.exit(1) obj = journal.get_event(user, uid) show_object(obj) diff -r e811fc71e425 -r f5b485cc5a93 tools/make_freebusy.py --- a/tools/make_freebusy.py Tue Oct 17 17:43:42 2017 +0200 +++ b/tools/make_freebusy.py Tue Oct 17 22:58:26 2017 +0200 @@ -278,9 +278,9 @@ # Obtain store-related objects or delegate this to the Client initialiser. - store = get_store(store_type, store_dir) - publisher = get_publisher(publishing_dir) - journal = get_journal(store_type, journal_dir) + store = store_dir and get_store(store_type, store_dir) or None + publisher = publishing_dir and get_publisher(publishing_dir) or None + journal = journal_dir and get_journal(store_type, journal_dir) or None # Determine which kind of object will be accessed. diff -r e811fc71e425 -r f5b485cc5a93 tools/set_delegates.py --- a/tools/set_delegates.py Tue Oct 17 17:43:42 2017 +0200 +++ b/tools/set_delegates.py Tue Oct 17 22:58:26 2017 +0200 @@ -82,6 +82,10 @@ # Obtain store-related objects. journal = get_journal(store_type, journal_dir) + if not journal: + print >>sys.stderr, "Journal not present." + sys.exit(1) + f = getreader("utf-8")(sys.stdin) delegates = get_table_from_stream(f, tab_separated=False) journal.set_delegates(quota, [value for (value,) in delegates]) diff -r e811fc71e425 -r f5b485cc5a93 tools/set_quota_groups.py --- a/tools/set_quota_groups.py Tue Oct 17 17:43:42 2017 +0200 +++ b/tools/set_quota_groups.py Tue Oct 17 22:58:26 2017 +0200 @@ -93,6 +93,10 @@ # Obtain store-related objects. journal = get_journal(store_type, journal_dir) + if not journal: + print >>sys.stderr, "Journal not present." + sys.exit(1) + f = getreader("utf-8")(sys.stdin) groups = dict(get_table_from_stream(f, tab_separated=False)) journal.set_groups(quota, groups) diff -r e811fc71e425 -r f5b485cc5a93 tools/set_quota_limits.py --- a/tools/set_quota_limits.py Tue Oct 17 17:43:42 2017 +0200 +++ b/tools/set_quota_limits.py Tue Oct 17 22:58:26 2017 +0200 @@ -93,6 +93,10 @@ # Obtain store-related objects. journal = get_journal(store_type, journal_dir) + if not journal: + print >>sys.stderr, "Journal not present." + sys.exit(1) + f = getreader("utf-8")(sys.stdin) limits = dict(get_table_from_stream(f, tab_separated=False)) journal.set_limits(quota, limits) diff -r e811fc71e425 -r f5b485cc5a93 tools/update_quotas.py --- a/tools/update_quotas.py Tue Oct 17 17:43:42 2017 +0200 +++ b/tools/update_quotas.py Tue Oct 17 22:58:26 2017 +0200 @@ -173,6 +173,9 @@ # Obtain store-related objects. journal = get_journal(store_type, journal_dir) + if not journal: + print >>sys.stderr, "Journal not present." + sys.exit(1) # Obtain a list of users for processing.