import routes
from webob import Request, exc
- from mediagoblin import routing, util, storage, staticdirect
- from mediagoblin.init.config import (
- read_mediagoblin_config, generate_validation_report)
+ from mediagoblin import routing, util, storage
from mediagoblin.db.open import setup_connection_and_db_from_config
+from mediagoblin.db.util import MigrationManager
from mediagoblin.mg_globals import setup_globals
from mediagoblin.init.celery import setup_celery_from_config
- from mediagoblin.init import get_jinja_loader
- from mediagoblin.workbench import WorkbenchManager
-
-
- class Error(Exception): pass
- class ImproperlyConfigured(Error): pass
+ from mediagoblin.init import get_jinja_loader, get_staticdirector, \
+ setup_global_and_app_config, setup_workbench
class MediaGoblinApp(object):
port = app_config.get('db_port')
if port:
port = asint(port)
- connection = mongokit.Connection(
- app_config.get('db_host'), port)
+
+ if use_pymongo:
+ connection = pymongo.Connection(
+ app_config.get('db_host'), port)
+ else:
+ connection = mongokit.Connection(
+ app_config.get('db_host'), port)
return connection
-def setup_connection_and_db_from_config(app_config):
- connection = connect_database_from_config(app_config)
++
+def setup_connection_and_db_from_config(app_config, use_pymongo=False):
+ """
+ Setup connection and database from config.
+
+ Optionally use pymongo instead of mongokit.
+ """
+ connection = connect_database_from_config(app_config, use_pymongo)
- database_path = app_config.get('db_name', 'mediagoblin')
+ database_path = app_config['db_name']
db = connection[database_path]
- models.register_models(connection)
- # Could configure indexes here on db
+
+ if not use_pymongo:
+ models.register_models(connection)
+
return (connection, db)