1.1 --- a/imiptools/__init__.py Tue Oct 17 23:30:18 2017 +0200
1.2 +++ b/imiptools/__init__.py Wed Oct 18 00:18:37 2017 +0200
1.3 @@ -25,7 +25,8 @@
1.4 from imiptools.content import handle_itip_part
1.5 from imiptools.data import get_address, get_addresses, get_uri
1.6 from imiptools.mail import Messenger
1.7 -from imiptools.stores import get_store, get_publisher, get_journal
1.8 +from imiptools.stores import get_store, get_publisher, get_journal, \
1.9 + StoreInitialisationError
1.10 import sys, os
1.11
1.12 # Postfix exit codes.
1.13 @@ -71,15 +72,21 @@
1.14
1.15 def get_publisher(self):
1.16
1.17 - "Return any configured publisher or None if not explicitly configured."
1.18 + "Return any configured publisher or None if not configured."
1.19
1.20 - return self.publishing_dir and get_publisher(self.publishing_dir) or None
1.21 + try:
1.22 + return get_publisher(self.publishing_dir)
1.23 + except StoreInitialisationError:
1.24 + return None
1.25
1.26 def get_journal(self):
1.27
1.28 - "Return any configured journal or None if not explicitly configured."
1.29 + "Return any configured journal or None if not configured."
1.30
1.31 - return self.journal_dir and get_journal(self.store_type, self.journal_dir) or None
1.32 + try:
1.33 + return get_journal(self.store_type, self.journal_dir)
1.34 + except StoreInitialisationError:
1.35 + return None
1.36
1.37 def process(self, f, original_recipients):
1.38
2.1 --- a/imiptools/stores/__init__.py Tue Oct 17 23:30:18 2017 +0200
2.2 +++ b/imiptools/stores/__init__.py Wed Oct 18 00:18:37 2017 +0200
2.3 @@ -20,6 +20,7 @@
2.4 """
2.5
2.6 from imiptools.config import settings
2.7 +from imiptools.stores.common import StoreInitialisationError
2.8 from imiptools.stores.manifest import stores
2.9
2.10 # Access functions.
2.11 @@ -42,7 +43,7 @@
2.12 """
2.13
2.14 return stores["file"].Publisher(
2.15 - publishing_dir or settings["PUBLISHING_DIR"])
2.16 + publishing_dir or settings["PUBLISH_DIR"])
2.17
2.18 def get_journal(store_type=None, journal_dir=None):
2.19
3.1 --- a/imiptools/stores/common.py Tue Oct 17 23:30:18 2017 +0200
3.2 +++ b/imiptools/stores/common.py Wed Oct 18 00:18:37 2017 +0200
3.3 @@ -21,6 +21,12 @@
3.4
3.5 from imiptools.dates import format_datetime, get_datetime
3.6
3.7 +class StoreInitialisationError(Exception):
3.8 +
3.9 + "An error occurring when the initialisation of a store fails."
3.10 +
3.11 + pass
3.12 +
3.13 class StoreBase:
3.14
3.15 "The core operations of a data store."
4.1 --- a/imiptools/stores/database/postgresql.py Tue Oct 17 23:30:18 2017 +0200
4.2 +++ b/imiptools/stores/database/postgresql.py Wed Oct 18 00:18:37 2017 +0200
4.3 @@ -20,6 +20,7 @@
4.4 """
4.5
4.6 from imiptools.config import settings
4.7 +from imiptools.stores.common import StoreInitialisationError
4.8 from imiptools.stores.database.common import DatabaseStore, DatabaseJournal
4.9 import psycopg2
4.10
4.11 @@ -34,7 +35,11 @@
4.12
4.13 "Interpret 'store_dir' as a connection string."
4.14
4.15 - connection = psycopg2.connect(store_dir or STORE_DIR)
4.16 + try:
4.17 + connection = psycopg2.connect(store_dir or STORE_DIR)
4.18 + except psycopg2.OperationalError, exc:
4.19 + raise StoreInitialisationError, exc
4.20 +
4.21 connection.autocommit = True
4.22 DatabaseStore.__init__(self, connection, psycopg2.paramstyle)
4.23
4.24 @@ -54,7 +59,11 @@
4.25
4.26 "Interpret 'store_dir' as a connection string."
4.27
4.28 - connection = psycopg2.connect(store_dir or JOURNAL_DIR)
4.29 + try:
4.30 + connection = psycopg2.connect(store_dir or JOURNAL_DIR)
4.31 + except psycopg2.OperationalError, exc:
4.32 + raise StoreInitialisationError, exc
4.33 +
4.34 connection.autocommit = True
4.35 DatabaseJournal.__init__(self, connection, psycopg2.paramstyle)
4.36
5.1 --- a/imiptools/stores/file.py Tue Oct 17 23:30:18 2017 +0200
5.2 +++ b/imiptools/stores/file.py Wed Oct 18 00:18:37 2017 +0200
5.3 @@ -19,7 +19,8 @@
5.4 this program. If not, see <http://www.gnu.org/licenses/>.
5.5 """
5.6
5.7 -from imiptools.stores.common import StoreBase, PublisherBase, JournalBase
5.8 +from imiptools.stores.common import StoreBase, PublisherBase, JournalBase, \
5.9 + StoreInitialisationError
5.10
5.11 from datetime import datetime
5.12 from imiptools.config import settings
5.13 @@ -62,7 +63,10 @@
5.14 "A file store of tabular free/busy data and objects."
5.15
5.16 def __init__(self, store_dir=None):
5.17 - FileBase.__init__(self, store_dir or STORE_DIR)
5.18 + try:
5.19 + FileBase.__init__(self, store_dir or STORE_DIR)
5.20 + except OSError, exc:
5.21 + raise StoreInitialisationError, exc
5.22
5.23 # Store object access.
5.24
5.25 @@ -707,7 +711,10 @@
5.26 "A publisher of objects."
5.27
5.28 def __init__(self, store_dir=None):
5.29 - FileBase.__init__(self, store_dir or PUBLISH_DIR)
5.30 + try:
5.31 + FileBase.__init__(self, store_dir or PUBLISH_DIR)
5.32 + except OSError, exc:
5.33 + raise StoreInitialisationError, exc
5.34
5.35 def set_freebusy(self, user, freebusy):
5.36