summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-08-21 22:33:09 +0200
committerGeorg Brandl <georg@python.org>2010-08-21 22:33:09 +0200
commit70e440f7c9fd041a51087abfc4dd7efdfe74b916 (patch)
treeee6812efd7de0d796cb0fcf37cceb5aeab72b611
parent86fce1ff9d13f8d661c7c67fb5e3626b9d11252d (diff)
downloadsphinx-70e440f7c9fd041a51087abfc4dd7efdfe74b916.tar.gz
Move default sqlalchemy engine creation to storage backend.
-rw-r--r--sphinx/websupport/__init__.py12
-rw-r--r--sphinx/websupport/storage/sqlalchemystorage.py8
2 files changed, 10 insertions, 10 deletions
diff --git a/sphinx/websupport/__init__.py b/sphinx/websupport/__init__.py
index f2d2ba45..30303132 100644
--- a/sphinx/websupport/__init__.py
+++ b/sphinx/websupport/__init__.py
@@ -65,12 +65,12 @@ class WebSupport(object):
# SQLAlchemy backend.
from sphinx.websupport.storage.sqlalchemystorage \
import SQLAlchemyStorage
- from sqlalchemy import create_engine
- db_path = path.join(self.datadir, 'db', 'websupport.db')
- ensuredir(path.dirname(db_path))
- uri = storage or 'sqlite:///%s' % db_path
- engine = create_engine(uri)
- self.storage = SQLAlchemyStorage(engine)
+ if not storage:
+ # no explicit DB path given; create default sqlite database
+ db_path = path.join(self.datadir, 'db', 'websupport.db')
+ ensuredir(path.dirname(db_path))
+ storage = 'sqlite:///' + db_path
+ self.storage = SQLAlchemyStorage(storage)
def _init_templating(self):
import sphinx
diff --git a/sphinx/websupport/storage/sqlalchemystorage.py b/sphinx/websupport/storage/sqlalchemystorage.py
index baef2481..dea2eea0 100644
--- a/sphinx/websupport/storage/sqlalchemystorage.py
+++ b/sphinx/websupport/storage/sqlalchemystorage.py
@@ -32,11 +32,11 @@ class SQLAlchemyStorage(StorageBackend):
A :class:`.StorageBackend` using SQLAlchemy.
"""
- def __init__(self, engine):
- self.engine = engine
- Base.metadata.bind = engine
+ def __init__(self, uri):
+ self.engine = sqlalchemy.create_engine(uri)
+ Base.metadata.bind = self.engine
Base.metadata.create_all()
- Session.configure(bind=engine)
+ Session.configure(bind=self.engine)
def pre_build(self):
self.build_session = Session()