diff options
| author | Barry Warsaw | 2007-08-01 16:11:08 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2007-08-01 16:11:08 -0400 |
| commit | f8a6c46455a409125dcc0fcace7d7116898b0319 (patch) | |
| tree | 4d1c942d92e4b63eb8f000e25477079c14bb5346 /Mailman/initialize.py | |
| parent | d72336c1e5932158f6e1f80e5ea9e90d264b7c52 (diff) | |
| parent | 7a7826e112a1d3f1999cb7a11e6df98cfcb712c9 (diff) | |
| download | mailman-f8a6c46455a409125dcc0fcace7d7116898b0319.tar.gz mailman-f8a6c46455a409125dcc0fcace7d7116898b0319.tar.zst mailman-f8a6c46455a409125dcc0fcace7d7116898b0319.zip | |
Diffstat (limited to 'Mailman/initialize.py')
| -rw-r--r-- | Mailman/initialize.py | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/Mailman/initialize.py b/Mailman/initialize.py index 9dee94cbe..9d16600ef 100644 --- a/Mailman/initialize.py +++ b/Mailman/initialize.py @@ -26,12 +26,17 @@ 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, IMessageStore, IUserManager) + DOT = '.' @@ -55,17 +60,46 @@ 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 + verifyObject(IMessageStore, db.message_store) + Mailman.configuration.config.message_store = db.message_store def initialize(config=None, propagate_logs=False): |
