summaryrefslogtreecommitdiff
path: root/Mailman/database
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/database
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/database')
-rw-r--r--Mailman/database/__init__.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/Mailman/database/__init__.py b/Mailman/database/__init__.py
index 6c6312d0a..d50c33973 100644
--- a/Mailman/database/__init__.py
+++ b/Mailman/database/__init__.py
@@ -20,30 +20,45 @@ from __future__ import with_statement
import os
from elixir import objectstore
+from zope.interface import implements
+from Mailman.interfaces import IDatabase
from Mailman.database.listmanager import ListManager
from Mailman.database.usermanager import UserManager
+__metaclass__ = type
__all__ = [
- 'initialize',
- 'flush',
+ 'StockDatabase',
+ 'flush', # for test convenience
]
+flush = None
+
-def initialize():
- from Mailman.LockFile import LockFile
- from Mailman.configuration import config
- from Mailman.database import model
- # Serialize this so we don't get multiple processes trying to create the
- # database at the same time.
- lockfile = os.path.join(config.LOCK_DIR, '<dbcreatelock>')
- with LockFile(lockfile):
- model.initialize()
- config.list_manager = ListManager()
- config.user_manager = UserManager()
- flush()
+class StockDatabase:
+ implements(IDatabase)
+
+ def __init__(self):
+ # Expose the flush() method for test case convenience using the stock
+ # database.
+ global flush
+ flush = self.flush
+ self.list_manager = None
+ self.user_manager = None
+ def initialize(self):
+ from Mailman.LockFile import LockFile
+ from Mailman.configuration import config
+ from Mailman.database import model
+ # Serialize this so we don't get multiple processes trying to create the
+ # database at the same time.
+ lockfile = os.path.join(config.LOCK_DIR, '<dbcreatelock>')
+ with LockFile(lockfile):
+ model.initialize()
+ self.list_manager = ListManager()
+ self.user_manager = UserManager()
+ self.flush()
-def flush():
- objectstore.flush()
+ def flush(self):
+ objectstore.flush()