summaryrefslogtreecommitdiff
path: root/Mailman/initialize.py
diff options
context:
space:
mode:
authorBarry Warsaw2007-07-24 18:45:25 -0400
committerBarry Warsaw2007-07-24 18:45:25 -0400
commit7a7826e112a1d3f1999cb7a11e6df98cfcb712c9 (patch)
treea4c0679185aeb4f4e482e88198b6bee8737837f2 /Mailman/initialize.py
parent8158f01c930d856b0ff892aab53cfbbcc25c85ec (diff)
downloadmailman-7a7826e112a1d3f1999cb7a11e6df98cfcb712c9.tar.gz
mailman-7a7826e112a1d3f1999cb7a11e6df98cfcb712c9.tar.zst
mailman-7a7826e112a1d3f1999cb7a11e6df98cfcb712c9.zip
Add setuptools plug-in entry point for defining different database backends.
Now someone could distribute a setuptools package that provided say, a MySQL database implementation and very easily override the stock database. How awesome is setuptools? Removed MANAGERS_INIT_FUNCTION since setuptools gives us a much more standard way of defining this plug-in entry point. Remove other old crud from Defaults.py. Restructure our own 'stock' database backend to be a plugin so it's totally on par with any other package. The only special case is that if more than one such entry point is defined, we filter out the 'stock' one (i.e. ours) under the assumption that the user is overriding it. If we still have more than one plug-in, it's an error. Restructure the initialization subsystem to use the plug-in, doing all the proper assertions and what not. The IDatabase interface defines what the database back-end plugin must provide. I've no doubt this will eventually need a bit more fleshing out, but it gives all this stuff a principled hook point instead of something ad-hoc.
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):