~jimmy-sigint/mailman/atomia_package_branch

« back to all changes in this revision

Viewing changes to src/mailman/database/factory.py

  • Committer: Barry Warsaw
  • Date: 2012-07-26 04:22:19 UTC
  • mfrom: (7149.2.19 bug-971013)
  • Revision ID: barry@list.org-20120726042219-o4asb3r7f6hil65t
 * The policy for archiving has now been collapsed into a single enum, called
   ArchivePolicy.  This describes the three states of never archive, archive
   privately, and archive_publicly. (LP: #967238)

Database
--------
 * Schema migrations (LP: #971013)
   - include_list_post_header -> allow_list_posts
   - news_prefix_subject_too  -> nntp_prefix_subject_too
   - news_moderation          -> newsgroup_moderation
   - archive and archive_private have been collapsed into archive_policy.
   - nntp_host has been removed.
 * The PostgreSQL port of the schema accidentally added a moderation_callback
   column to the mailinglist table.  Since this is unused in Mailman, it was
   simply commented out of the base schema for PostgreSQL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2012 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
 
6
# the terms of the GNU General Public License as published by the Free
 
7
# Software Foundation, either version 3 of the License, or (at your option)
 
8
# any later version.
 
9
#
 
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
# more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
"""Database factory."""
 
19
 
 
20
from __future__ import absolute_import, print_function, unicode_literals
 
21
 
 
22
__metaclass__ = type
 
23
__all__ = [
 
24
    'DatabaseFactory',
 
25
    'DatabaseTemporaryFactory',
 
26
    'DatabaseTestingFactory',
 
27
    ]
 
28
 
 
29
 
 
30
import types
 
31
 
 
32
from zope.component import getAdapter
 
33
from zope.interface import implementer
 
34
from zope.interface.verify import verifyObject
 
35
 
 
36
from mailman.config import config
 
37
from mailman.interfaces.database import (
 
38
    IDatabase, IDatabaseFactory, ITemporaryDatabase)
 
39
from mailman.utilities.modules import call_name
 
40
 
 
41
 
 
42
 
 
43
@implementer(IDatabaseFactory)
 
44
class DatabaseFactory:
 
45
    """Create a new database."""
 
46
 
 
47
    @staticmethod
 
48
    def create():
 
49
        """See `IDatabaseFactory`."""
 
50
        database_class = config.database['class']
 
51
        database = call_name(database_class)
 
52
        verifyObject(IDatabase, database)
 
53
        database.initialize()
 
54
        database.load_migrations()
 
55
        database.commit()
 
56
        return database
 
57
 
 
58
 
 
59
 
 
60
def _reset(self):
 
61
    """See `IDatabase`."""
 
62
    from mailman.database.model import ModelMeta
 
63
    self.store.rollback()
 
64
    self._pre_reset(self.store)
 
65
    ModelMeta._reset(self.store)
 
66
    self._post_reset(self.store)
 
67
    self.store.commit()
 
68
 
 
69
 
 
70
@implementer(IDatabaseFactory)
 
71
class DatabaseTestingFactory:
 
72
    """Create a new database for testing."""
 
73
 
 
74
    @staticmethod
 
75
    def create():
 
76
        """See `IDatabaseFactory`."""
 
77
        database_class = config.database['class']
 
78
        database = call_name(database_class)
 
79
        verifyObject(IDatabase, database)
 
80
        database.initialize()
 
81
        database.load_migrations()
 
82
        database.commit()
 
83
        # Make _reset() a bound method of the database instance.
 
84
        database._reset = types.MethodType(_reset, database)
 
85
        return database
 
86
 
 
87
 
 
88
 
 
89
@implementer(IDatabaseFactory)
 
90
class DatabaseTemporaryFactory:
 
91
    """Create a temporary database for some of the migration tests."""
 
92
 
 
93
    @staticmethod
 
94
    def create():
 
95
        """See `IDatabaseFactory`."""
 
96
        database_class_name = config.database['class']
 
97
        database = call_name(database_class_name)
 
98
        verifyObject(IDatabase, database)
 
99
        adapted_database = getAdapter(
 
100
            database, ITemporaryDatabase, database.TAG)
 
101
        return adapted_database