diff options
| author | Barry Warsaw | 2007-11-18 16:38:59 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2007-11-18 16:38:59 -0500 |
| commit | eff07b15bedb17e51271a75f849447100b201734 (patch) | |
| tree | c429a9e854007a64ad8373f97295f66a1ac190c7 /Mailman/database/listmanager.py | |
| parent | 2b7304d722e9ca628d6550dbb024dfa78322e91f (diff) | |
| parent | 8a7be9204a9170f9d9b0eb79c2726df0c7a1b4a9 (diff) | |
| download | mailman-eff07b15bedb17e51271a75f849447100b201734.tar.gz mailman-eff07b15bedb17e51271a75f849447100b201734.tar.zst mailman-eff07b15bedb17e51271a75f849447100b201734.zip | |
Convert to the Storm Python ORM <storm.canonical.com>. There were several
reasons for this, but most importantly, the changes from SQLAlchemy/Elixir 0.3
to 0.4 were substantial and caused a lot of work. This work unfortunately did
not result in a working branch due to very strange and inconsistent behavior
with Unicode columns. Sometimes such columns would return Unicode, sometimes
8-bit strings, with no rhyme or reason. I gave up debugging this after many
hours of head scratching.
Oh yeah, no more flush!
Storm enforces Unicode columns, which is very nice, though requires us to add
lots of 'u's in places we didn't have them before. Ultimately, this is a good
thing so that the core of Mailman will be Unicode consistent.
One thing I still want to clean up after this, is the function-scoped imports
in the model code. Part of the reason for the separate model classes was to
avoid this, but for now, we'll live with it. Storm's architecture requires us
to maintain a database-table-class registry for simple clearing after tests
in Database._reset(). This is made fairly simple by Storm allowing us to use
our own metaclass for model classes.
Storm does require that we write our own SQL files, which is a downside, but I
think our schema will be easy enough that this won't be a huge burden. Plus
we have a head-start <wink>.
Another cool thing about Storm is the explicit use of stores for objects.
This should eventually allow me to flesh out my idea of storage pillars for 1)
lists, 2) users, 3) messages.
Some other changes:
- pylint and pyflakes cleanups
- SQLALCHEMY_ENGINE_URL -> DEFAULT_DATABASE_URL
- Don't import-* from Version in Defaults.py
- Add interface method to Mailman.Message.Message so that __getitem__() and
get_all() always return Unicode headers, even when the underlying objects
are strings. This should generally be safe as headers are required by RFC
to be within the ASCII range.
- Fix bin/arch.py to use proper initialization.
Diffstat (limited to 'Mailman/database/listmanager.py')
| -rw-r--r-- | Mailman/database/listmanager.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/Mailman/database/listmanager.py b/Mailman/database/listmanager.py index 46f0aa859..48e7fe62c 100644 --- a/Mailman/database/listmanager.py +++ b/Mailman/database/listmanager.py @@ -15,17 +15,15 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -"""SQLAlchemy/Elixir based provider of IListManager.""" +"""A mailing list manager.""" import datetime -from elixir import * from zope.interface import implements from Mailman import Errors from Mailman.Utils import split_listname, fqdn_listname from Mailman.configuration import config -from Mailman.database.model import MailingList, Pendings from Mailman.interfaces import IListManager @@ -34,21 +32,30 @@ class ListManager(object): implements(IListManager) def create(self, fqdn_listname): + # Avoid circular imports. + from Mailman.database.model import MailingList listname, hostname = split_listname(fqdn_listname) - mlist = MailingList.get_by(list_name=listname, - host_name=hostname) + mlist = config.db.store.find( + MailingList, + MailingList.list_name == listname, + MailingList.host_name == hostname).one() if mlist: raise Errors.MMListAlreadyExistsError(fqdn_listname) mlist = MailingList(fqdn_listname) mlist.created_at = datetime.datetime.now() + config.db.store.add(mlist) return mlist def delete(self, mlist): - mlist.delete() + config.db.store.remove(mlist) def get(self, fqdn_listname): + # Avoid circular imports. + from Mailman.database.model import MailingList listname, hostname = split_listname(fqdn_listname) - mlist = MailingList.get_by(list_name=listname, host_name=hostname) + mlist = config.db.store.find(MailingList, + list_name=listname, + host_name=hostname).one() if mlist is not None: # XXX Fixme mlist._restore() @@ -63,5 +70,7 @@ class ListManager(object): @property def names(self): - for mlist in MailingList.query.filter_by().all(): + # Avoid circular imports. + from Mailman.database.model import MailingList + for mlist in config.db.store.find(MailingList): yield fqdn_listname(mlist.list_name, mlist.host_name) |
