Move "connect to database" into db/util.py
This commit is contained in:
parent
0f18ed8f5e
commit
a4bae8700e
@ -17,12 +17,12 @@
|
|||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
import routes
|
import routes
|
||||||
import mongokit
|
|
||||||
from paste.deploy.converters import asbool, asint
|
from paste.deploy.converters import asbool, asint
|
||||||
from webob import Request, exc
|
from webob import Request, exc
|
||||||
|
|
||||||
from mediagoblin import routing, util, storage, staticdirect
|
from mediagoblin import routing, util, storage, staticdirect
|
||||||
from mediagoblin.db import models
|
from mediagoblin.db import models
|
||||||
|
from mediagoblin.db.util import connect_database
|
||||||
from mediagoblin.globals import setup_globals
|
from mediagoblin.globals import setup_globals
|
||||||
from mediagoblin.celery_setup import setup_celery_from_config
|
from mediagoblin.celery_setup import setup_celery_from_config
|
||||||
|
|
||||||
@ -118,11 +118,7 @@ class MediaGoblinApp(object):
|
|||||||
|
|
||||||
def paste_app_factory(global_config, **app_config):
|
def paste_app_factory(global_config, **app_config):
|
||||||
# Get the database connection
|
# Get the database connection
|
||||||
port = app_config.get('db_port')
|
connection = connect_database(app_config)
|
||||||
if port:
|
|
||||||
port = asint(port)
|
|
||||||
connection = mongokit.Connection(
|
|
||||||
app_config.get('db_host'), port)
|
|
||||||
|
|
||||||
# Set up the storage systems.
|
# Set up the storage systems.
|
||||||
public_store = storage.storage_system_from_paste_config(
|
public_store = storage.storage_system_from_paste_config(
|
||||||
|
11
mediagoblin/db/util.py
Normal file
11
mediagoblin/db/util.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user