diff options
| author | Abhilash Raj | 2014-09-19 22:41:56 +0530 |
|---|---|---|
| committer | Abhilash Raj | 2014-09-19 22:41:56 +0530 |
| commit | c339f06cca6ddf1d28cde2614a94c2a0c905957a (patch) | |
| tree | 89682556800053817cb61f2a7b039f39dd7ddd39 /src | |
| parent | 6dd2ac32ee1f1e8f588c08fd5363f0f794d0a6b1 (diff) | |
| download | mailman-c339f06cca6ddf1d28cde2614a94c2a0c905957a.tar.gz mailman-c339f06cca6ddf1d28cde2614a94c2a0c905957a.tar.zst mailman-c339f06cca6ddf1d28cde2614a94c2a0c905957a.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/database/base.py | 57 | ||||
| -rw-r--r-- | src/mailman/database/model.py | 17 | ||||
| -rw-r--r-- | src/mailman/model/address.py | 1 | ||||
| -rw-r--r-- | src/mailman/model/message.py | 1 | ||||
| -rw-r--r-- | src/mailman/model/pending.py | 1 | ||||
| -rw-r--r-- | src/mailman/model/requests.py | 1 | ||||
| -rw-r--r-- | src/mailman/model/uid.py | 1 | ||||
| -rw-r--r-- | src/mailman/model/user.py | 1 | ||||
| -rw-r--r-- | src/mailman/model/version.py | 1 |
9 files changed, 26 insertions, 55 deletions
diff --git a/src/mailman/database/base.py b/src/mailman/database/base.py index 5eec853d6..f379b3124 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -49,9 +49,12 @@ NL = '\n' class SABaseDatabase: """The database base class for use with SQLAlchemy. - Use this as a base class for your DB_Specific derived classes. + Use this as a base class for your DB-Specific derived classes. """ - TAG='' + # Tag used to distinguish the database being used. Override this in base + # classes. + + TAG = '' def __init__(self): self.url = None @@ -59,17 +62,18 @@ class SABaseDatabase: self.transaction = None def begin(self): + """See `IDatabase`.""" + # SA does this for us. pass def commit(self): + """See `IDatabase`.""" self.store.commit() def abort(self): + """See `IDatabase`.""" self.store.rollback() - def _prepare(self, url): - pass - def _database_exists(self): """Return True if the database exists and is initialized. @@ -97,11 +101,27 @@ class SABaseDatabase: database-specific post-removal cleanup. """ pass + def initialize(self, debug=None): + """See `IDatabase`""" + # Calculate the engine url url = expand(config.database.url, config.paths) log.debug('Database url: %s', url) + # XXX By design of SQLite, database file creation does not honor + # umask. See their ticket #1193: + # http://www.sqlite.org/cvstrac/tktview?tn=1193,31 + # + # This sucks for us because the mailman.db file /must/ be group + # writable, however even though we guarantee our umask is 002 here, it + # still gets created without the necessary g+w permission, due to + # SQLite's policy. This should only affect SQLite engines because its + # the only one that creates a little file on the local file system. + # This kludges around their bug by "touch"ing the database file before + # SQLite has any chance to create it, thus honoring the umask and + # ensuring the right permissions. We only try to do this for SQLite + # engines, and yes, we could have chmod'd the file after the fact, but + # half dozen and all... self.url = url - self._prepare(url) self.engine = create_engine(url) session = sessionmaker(bind=self.engine) self.store = session() @@ -133,31 +153,6 @@ class SABaseDatabase: if statement.strip() != '': store.execute(statement + ';') - def load_schema(self, store, version, filename, module_path): - """Load the schema from a file. - - This is a helper method for migration classes to call. - - :param store: The Storm store to load the schema into. - :type store: storm.locals.Store` - :param version: The schema version identifier of the form - YYYYMMDDHHMMSS. - :type version: string - :param filename: The file name containing the schema to load. Pass - `None` if there is no schema file to load. - :type filename: string - :param module_path: The fully qualified Python module path to the - migration module being loaded. This is used to record information - for use by the test suite. - :type module_path: string - """ - if filename is not None: - contents = resource_string('mailman.database.schema', filename) - self.load_sql(store, contents) - # Add a marker that indicates the migration version being applied. - store.add(Version(component='schema', version=version)) - - @staticmethod def _make_temporary(): diff --git a/src/mailman/database/model.py b/src/mailman/database/model.py index dedd7a34b..d86ebb80e 100644 --- a/src/mailman/database/model.py +++ b/src/mailman/database/model.py @@ -35,23 +35,6 @@ from mailman.config import config class ModelMeta(object): """Do more magic on table classes.""" - _class_registry = set() - - def __init__(self, name, bases, dict): - # Before we let the base class do it's thing, force an __tablename__ - # property to enforce our table naming convention. - self.__tablename__ = name.lower() - # super(ModelMeta, self).__init__(name, bases, dict) - # Register the model class so that it can be more easily cleared. - # This is required by the test framework so that the corresponding - # table can be reset between tests. - # - # The PRESERVE flag indicates whether the table should be reset or - # not. We have to handle the actual Model base class explicitly - # because it does not correspond to a table in the database. - if not getattr(self, 'PRESERVE', False) and name != 'Model': - ModelMeta._class_registry.add(self) - @staticmethod def _reset(db): meta = Model.metadata diff --git a/src/mailman/model/address.py b/src/mailman/model/address.py index fbe862829..7203a31a5 100644 --- a/src/mailman/model/address.py +++ b/src/mailman/model/address.py @@ -60,7 +60,6 @@ class Address(Model): backref=backref('Address', uselist=False)) def __init__(self, email, display_name): - super(Address, self).__init__() getUtility(IEmailValidator).validate(email) lower_case = email.lower() self.email = lower_case diff --git a/src/mailman/model/message.py b/src/mailman/model/message.py index b153d4909..39f33aa89 100644 --- a/src/mailman/model/message.py +++ b/src/mailman/model/message.py @@ -47,7 +47,6 @@ class Message(Model): @dbconnection def __init__(self, store, message_id, message_id_hash, path): - super(Message, self).__init__() self.message_id = message_id self.message_id_hash = message_id_hash self.path = path diff --git a/src/mailman/model/pending.py b/src/mailman/model/pending.py index 30aae074c..97d394721 100644 --- a/src/mailman/model/pending.py +++ b/src/mailman/model/pending.py @@ -71,7 +71,6 @@ class Pended(Model): __tablename__ = 'pended' def __init__(self, token, expiration_date): - super(Pended, self).__init__() self.token = token self.expiration_date = expiration_date diff --git a/src/mailman/model/requests.py b/src/mailman/model/requests.py index 1b72f78f3..88ad0e407 100644 --- a/src/mailman/model/requests.py +++ b/src/mailman/model/requests.py @@ -153,7 +153,6 @@ class _Request(Model): mailing_list = relationship('MailingList') def __init__(self, key, request_type, mailing_list, data_hash): - super(_Request, self).__init__() self.key = key self.request_type = request_type self.mailing_list = mailing_list diff --git a/src/mailman/model/uid.py b/src/mailman/model/uid.py index 6486089fa..77f1b59bb 100644 --- a/src/mailman/model/uid.py +++ b/src/mailman/model/uid.py @@ -54,7 +54,6 @@ class UID(Model): @dbconnection def __init__(self, store, uid): - super(UID, self).__init__() self.uid = uid store.add(self) diff --git a/src/mailman/model/user.py b/src/mailman/model/user.py index 37fb29e65..cd47a5dac 100644 --- a/src/mailman/model/user.py +++ b/src/mailman/model/user.py @@ -79,7 +79,6 @@ class User(Model): @dbconnection def __init__(self, store, display_name=None, preferences=None): - super(User, self).__init__() self._created_on = date_factory.now() user_id = uid_factory.new_uid() assert store.query(User).filter_by(_user_id=user_id).count() == 0, ( diff --git a/src/mailman/model/version.py b/src/mailman/model/version.py index 8dc0d4e6c..95cf03dac 100644 --- a/src/mailman/model/version.py +++ b/src/mailman/model/version.py @@ -43,6 +43,5 @@ class Version(Model): PRESERVE = True def __init__(self, component, version): - super(Version, self).__init__() self.component = component self.version = version |
