~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to Mailman/database/model.py

  • Committer: Barry Warsaw
  • Date: 2007-12-08 16:51:36 UTC
  • Revision ID: barry@python.org-20071208165136-gcm3v8d7o3jbb0tt
Reorganize the database subpackage, primarily by removing the 'model'
subdirectory and updating all relevant imports.  Move of the circular
import problems have been eliminated in the process.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2007 by the Free Software Foundation, Inc.
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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,
 
16
# USA.
 
17
 
 
18
"""Base class for all database classes."""
 
19
 
 
20
__metaclass__ = type
 
21
__all__ = [
 
22
    'Model',
 
23
    ]
 
24
 
 
25
from storm.properties import PropertyPublisherMeta
 
26
 
 
27
 
 
28
 
 
29
class ModelMeta(PropertyPublisherMeta):
 
30
    """Do more magic on table classes."""
 
31
 
 
32
    _class_registry = set()
 
33
 
 
34
    def __init__(self, name, bases, dict):
 
35
        # Before we let the base class do it's thing, force an __storm_table__
 
36
        # property to enforce our table naming convention.
 
37
        self.__storm_table__ = name.lower()
 
38
        super(ModelMeta, self).__init__(name, bases, dict)
 
39
        # Register the model class so that it can be more easily cleared.
 
40
        # This is required by the test framework.
 
41
        if name == 'Model':
 
42
            return
 
43
        ModelMeta._class_registry.add(self)
 
44
 
 
45
    @staticmethod
 
46
    def _reset(store):
 
47
        for model_class in ModelMeta._class_registry:
 
48
            for row in store.find(model_class):
 
49
                store.remove(row)
 
50
 
 
51
 
 
52
 
 
53
class Model(object):
 
54
    """Like Storm's `Storm` subclass, but with a bit extra."""
 
55
    __metaclass__ = ModelMeta