From: Elrond Date: Tue, 17 May 2011 23:03:40 +0000 (+0200) Subject: Move "connect to database" into db/util.py X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a4bae8700e2186adb91d5c0a5198e7a8923143c6;p=mediagoblin.git Move "connect to database" into db/util.py --- diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 908bb19c..c94b5f6d 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -17,12 +17,12 @@ import urllib import routes -import mongokit from paste.deploy.converters import asbool, asint from webob import Request, exc from mediagoblin import routing, util, storage, staticdirect from mediagoblin.db import models +from mediagoblin.db.util import connect_database from mediagoblin.globals import setup_globals from mediagoblin.celery_setup import setup_celery_from_config @@ -118,11 +118,7 @@ class MediaGoblinApp(object): def paste_app_factory(global_config, **app_config): # Get the database connection - port = app_config.get('db_port') - if port: - port = asint(port) - connection = mongokit.Connection( - app_config.get('db_host'), port) + connection = connect_database(app_config) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py new file mode 100644 index 00000000..89e0dbef --- /dev/null +++ b/mediagoblin/db/util.py @@ -0,0 +1,11 @@ +import mongokit + + +def connect_database(app_config): + """Connect to the main database, take config from app_config""" + port = app_config.get('db_port') + if port: + port = asint(port) + connection = mongokit.Connection( + app_config.get('db_host'), port) + return connection