1 # Copyright (C) 2006-2007 by the Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 from __future__
import with_statement
27 from locknix
.lockfile
import Lock
28 from storm
.properties
import PropertyPublisherMeta
29 from zope
.interface
import implements
31 from Mailman
.interfaces
import IDatabase
32 from Mailman
.database
.listmanager
import ListManager
33 from Mailman
.database
.usermanager
import UserManager
34 from Mailman
.database
.messagestore
import MessageStore
42 self
.list_manager
= None
43 self
.user_manager
= None
44 self
.message_store
= None
49 def initialize(self
, debug
=None):
50 # Avoid circular imports.
51 from Mailman
.configuration
import config
52 from Mailman
.database
import model
53 from Mailman
.database
.model
import Pendings
54 from Mailman
.database
.model
import Requests
55 # Serialize this so we don't get multiple processes trying to create
56 # the database at the same time.
57 with
Lock(os
.path
.join(config
.LOCK_DIR
, 'dbcreate.lck')):
58 self
.store
= model
.initialize(debug
)
59 self
.list_manager
= ListManager()
60 self
.user_manager
= UserManager()
61 self
.message_store
= MessageStore()
62 self
.pendings
= Pendings()
63 self
.requests
= Requests()
66 for model_class
in _class_registry
:
67 for row
in self
.store
.find(model_class
):
68 self
.store
.remove(row
)
72 _class_registry
= set()
75 class ModelMeta(PropertyPublisherMeta
):
76 """Do more magic on table classes."""
78 def __init__(self
, name
, bases
, dict):
79 # Before we let the base class do it's thing, force an __storm_table__
80 # property to enforce our table naming convention.
81 self
.__storm
_table
__ = name
.lower()
82 super(ModelMeta
, self
).__init
__(name
, bases
, dict)
83 # Register the model class so that it can be more easily cleared.
84 # This is required by the test framework.
87 _class_registry
.add(self
)
91 """Like Storm's `Storm` subclass, but with a bit extra."""
92 __metaclass__
= ModelMeta