Move "connect to database" into db/util.py
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Tue, 17 May 2011 23:03:40 +0000 (01:03 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Tue, 17 May 2011 23:03:40 +0000 (01:03 +0200)
mediagoblin/app.py
mediagoblin/db/util.py [new file with mode: 0644]

index 908bb19cee0e7fa3b952d7b2b043c3a3108e6e41..c94b5f6d20603061e9e658571cfed047f20d3cf2 100644 (file)
 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 (file)
index 0000000..89e0dbe
--- /dev/null
@@ -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