summaryrefslogtreecommitdiff
path: root/Mailman/initialize.py
diff options
context:
space:
mode:
Diffstat (limited to 'Mailman/initialize.py')
-rw-r--r--Mailman/initialize.py49
1 files changed, 40 insertions, 9 deletions
diff --git a/Mailman/initialize.py b/Mailman/initialize.py
index 9dee94cbe..03c861066 100644
--- a/Mailman/initialize.py
+++ b/Mailman/initialize.py
@@ -26,12 +26,16 @@ by the command line arguments.
import os
import sys
+import pkg_resources
+
+from zope.interface.verify import verifyObject
import Mailman.configuration
-import Mailman.database
import Mailman.ext
import Mailman.loginit
+from Mailman.interfaces import IDatabase, IListManager, IUserManager
+
DOT = '.'
@@ -55,17 +59,44 @@ def initialize_1(config, propagate_logs):
Mailman.loginit.initialize(propagate_logs)
# Set up site extensions directory
Mailman.ext.__path__.append(Mailman.configuration.config.EXT_DIR)
- # Initialize the IListManager, IMemberManager, and IMessageManager
- modparts = Mailman.configuration.config.MANAGERS_INIT_FUNCTION.split(DOT)
- funcname = modparts.pop()
- modname = DOT.join(modparts)
- __import__(modname)
- initfunc = getattr(sys.modules[modname], funcname)
- initfunc()
def initialize_2():
- Mailman.database.initialize()
+ # Find all declared entry points in the mailman.database group. There
+ # must be exactly one or two such entry points defined. If there are two,
+ # then we remove the one called 'stock' since that's the one that we
+ # distribute and it's obviously being overridden. If we're still left
+ # with more than one after we filter out the stock one, it is an error.
+ entrypoints = list(pkg_resources.iter_entry_points('mailman.database'))
+ if len(entrypoints) == 0:
+ raise RuntimeError('No database entry points found')
+ elif len(entrypoints) == 1:
+ # Okay, this is the one to use.
+ entrypoint = entrypoints[0]
+ elif len(database) == 2:
+ # Find the one /not/ named 'stock'.
+ entrypoints = [ep for ep in entrypoints if ep.name <> 'stock']
+ if len(entrypoints) == 0:
+ raise RuntimeError('No database entry points found')
+ elif len(entrypoints) == 2:
+ raise RuntimeError('Too many database entry points defined')
+ else:
+ assert len(entrypoints) == 1, 'Insanity'
+ entrypoint = entrypoint[0]
+ else:
+ raise RuntimeError('Too many database entry points defined')
+ # Instantiate the database entry point, ensure that it's of the right
+ # type, and initialize it. Then stash the object on our configuration
+ # object.
+ ep_object = entrypoint.load()
+ db = ep_object()
+ verifyObject(IDatabase, db)
+ db.initialize()
+ Mailman.configuration.config.db = db
+ verifyObject(IListManager, db.list_manager)
+ Mailman.configuration.config.list_manager = db.list_manager
+ verifyObject(IUserManager, db.user_manager)
+ Mailman.configuration.config.user_manager = db.user_manager
def initialize(config=None, propagate_logs=False):