diff options
| author | Barry Warsaw | 2011-11-02 15:41:39 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2011-11-02 15:41:39 -0400 |
| commit | f48ca2a1aa74a1b0fe14003d9ceb37e146b46738 (patch) | |
| tree | 3df8d993612a41064d8a69b7de831bff2f57ff8e /src/mailman/database | |
| parent | f8456fef792eaa7b36a5b04072c5ad15d5fb6d48 (diff) | |
| download | mailman-f48ca2a1aa74a1b0fe14003d9ceb37e146b46738.tar.gz mailman-f48ca2a1aa74a1b0fe14003d9ceb37e146b46738.tar.zst mailman-f48ca2a1aa74a1b0fe14003d9ceb37e146b46738.zip | |
Diffstat (limited to 'src/mailman/database')
| -rw-r--r-- | src/mailman/database/base.py | 24 | ||||
| -rw-r--r-- | src/mailman/database/sqlite.py | 13 |
2 files changed, 23 insertions, 14 deletions
diff --git a/src/mailman/database/base.py b/src/mailman/database/base.py index 1e71341e0..bf5afd5d4 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -30,7 +30,6 @@ from flufl.lock import Lock from lazr.config import as_boolean from storm.cache import GenerationalCache from storm.locals import create_database, Store -from urlparse import urlparse from zope.interface import implements import mailman.version @@ -115,6 +114,15 @@ class StormBaseDatabase: """ pass + def _prepare(self, url): + """Prepare the database for creation. + + Some database backends need to do so me prep work before letting Storm + create the database. For example, we have to touch the SQLite .db + file first so that it has the proper file modes. + """ + pass + def _create(self, debug): # Calculate the engine url. url = expand(config.database.url, config.paths) @@ -134,7 +142,7 @@ class StormBaseDatabase: # engines, and yes, we could have chmod'd the file after the fact, but # half dozen and all... self.url = url - touch(url) + self._prepare(url) database = create_database(url) store = Store(database, GenerationalCache()) database.DEBUG = (as_boolean(config.database.debug) @@ -170,15 +178,3 @@ class StormBaseDatabase: from mailman.database.model import ModelMeta self.store.rollback() ModelMeta._reset(self.store) - - - -def touch(url): - parts = urlparse(url) - if parts.scheme <> 'sqlite': - return - path = os.path.normpath(parts.path) - fd = os.open(path, os.O_WRONLY | os.O_NONBLOCK | os.O_CREAT, 0666) - # Ignore errors - if fd > 0: - os.close(fd) diff --git a/src/mailman/database/sqlite.py b/src/mailman/database/sqlite.py index 30c4959b7..a68dc1eea 100644 --- a/src/mailman/database/sqlite.py +++ b/src/mailman/database/sqlite.py @@ -25,7 +25,10 @@ __all__ = [ ] +import os + from pkg_resources import resource_string +from urlparse import urlparse from mailman.database.base import StormBaseDatabase @@ -41,6 +44,16 @@ class SQLiteDatabase(StormBaseDatabase): store.execute(table_query)) return 'version' in table_names + def _prepare(self, url): + parts = urlparse(url) + assert parts.scheme == 'sqlite', ( + 'Database url mismatch (expected sqlite prefix): {0}'.format(url)) + path = os.path.normpath(parts.path) + fd = os.open(path, os.O_WRONLY | os.O_NONBLOCK | os.O_CREAT, 0666) + # Ignore errors + if fd > 0: + os.close(fd) + def _get_schema(self): """See `BaseDatabase`.""" return resource_string('mailman.database.sql', 'sqlite.sql') |
