diff options
-rw-r--r-- | mediagoblin/app.py | 19 | ||||
-rw-r--r-- | mediagoblin/celery_setup/from_celery.py | 14 | ||||
-rw-r--r-- | mediagoblin/db/__init__.py | 15 | ||||
-rw-r--r-- | mediagoblin/db/models.py (renamed from mediagoblin/models.py) | 0 | ||||
-rw-r--r-- | mediagoblin/db/open.py | 37 | ||||
-rw-r--r-- | mediagoblin/db/util.py | 20 | ||||
-rw-r--r-- | mediagoblin/process_media/__init__.py | 4 | ||||
-rw-r--r-- | mediagoblin/user_pages/views.py | 5 | ||||
-rw-r--r-- | mediagoblin/util.py | 4 | ||||
-rw-r--r-- | mediagoblin/views.py | 10 |
10 files changed, 90 insertions, 38 deletions
diff --git a/mediagoblin/app.py b/mediagoblin/app.py index d124558d..640ffc45 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -17,11 +17,11 @@ import urllib import routes -import mongokit -from paste.deploy.converters import asbool, asint +from paste.deploy.converters import asbool from webob import Request, exc -from mediagoblin import routing, util, models, storage, staticdirect +from mediagoblin import routing, util, storage, staticdirect +from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.globals import setup_globals from mediagoblin.celery_setup import setup_celery_from_config @@ -34,7 +34,7 @@ class MediaGoblinApp(object): """ Really basic wsgi app using routes and WebOb. """ - def __init__(self, connection, database_path, + def __init__(self, connection, db, public_store, queue_store, staticdirector, email_sender_address, email_debug_mode, @@ -48,8 +48,7 @@ class MediaGoblinApp(object): # Set up database self.connection = connection - self.db = connection[database_path] - models.register_models(connection) + self.db = db # set up routing self.routing = routing.get_mapper() @@ -117,11 +116,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, db = setup_connection_and_db_from_config(app_config) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( @@ -146,7 +141,7 @@ def paste_app_factory(global_config, **app_config): setup_celery_from_config(app_config, global_config) mgoblin_app = MediaGoblinApp( - connection, app_config.get('db_name', 'mediagoblin'), + connection, db, public_store=public_store, queue_store=queue_store, staticdirector=staticdirector, email_sender_address=app_config.get( diff --git a/mediagoblin/celery_setup/from_celery.py b/mediagoblin/celery_setup/from_celery.py index 55e638b9..0669e80c 100644 --- a/mediagoblin/celery_setup/from_celery.py +++ b/mediagoblin/celery_setup/from_celery.py @@ -16,11 +16,11 @@ import os -import mongokit from paste.deploy.loadwsgi import NicerConfigParser -from paste.deploy.converters import asint, asbool +from paste.deploy.converters import asbool -from mediagoblin import storage, models +from mediagoblin import storage +from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.celery_setup import setup_celery_from_config from mediagoblin.globals import setup_globals from mediagoblin import globals as mgoblin_globals @@ -68,13 +68,7 @@ def setup_self(setup_globals_func=setup_globals): settings_module=OUR_MODULENAME, set_environ=False) - port = mgoblin_section.get('db_port') - if port: - port = asint(port) - connection = mongokit.Connection( - mgoblin_section.get('db_host'), port) - db = connection[mgoblin_section.get('db_name', 'mediagoblin')] - models.register_models(connection) + connection, db = setup_connection_and_db_from_config(mgoblin_section) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( diff --git a/mediagoblin/db/__init__.py b/mediagoblin/db/__init__.py new file mode 100644 index 00000000..c129cbf8 --- /dev/null +++ b/mediagoblin/db/__init__.py @@ -0,0 +1,15 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. diff --git a/mediagoblin/models.py b/mediagoblin/db/models.py index 1bc1da60..1bc1da60 100644 --- a/mediagoblin/models.py +++ b/mediagoblin/db/models.py diff --git a/mediagoblin/db/open.py b/mediagoblin/db/open.py new file mode 100644 index 00000000..cae33394 --- /dev/null +++ b/mediagoblin/db/open.py @@ -0,0 +1,37 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import mongokit +from paste.deploy.converters import asint +from mediagoblin.db import models + + +def connect_database_from_config(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 + +def setup_connection_and_db_from_config(app_config): + connection = connect_database_from_config(app_config) + database_path = app_config.get('db_name', 'mediagoblin') + db = connection[database_path] + models.register_models(connection) + # Could configure indexes here on db + return (connection, db) diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py new file mode 100644 index 00000000..30615fca --- /dev/null +++ b/mediagoblin/db/util.py @@ -0,0 +1,20 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +# Imports that other modules might use +from pymongo import DESCENDING +from mongokit import ObjectId diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 3c4d0ca1..4f06a686 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -15,7 +15,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import Image -import mongokit +from mediagoblin.db.util import ObjectId from celery.task import task from mediagoblin.globals import database, queue_store, public_store @@ -27,7 +27,7 @@ THUMB_SIZE = 200, 200 @task def process_media_initial(media_id): entry = database.MediaEntry.one( - {'_id': mongokit.ObjectId(media_id)}) + {'_id': ObjectId(media_id)}) queued_filepath = entry['queued_media_file'] queued_file = queue_store.get_file(queued_filepath, 'r') diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index cb2c5875..d8665915 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -15,11 +15,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from webob import Response, exc -from pymongo import DESCENDING -from mongokit import ObjectId -import wtforms +from mediagoblin.db.util import ObjectId, DESCENDING from mediagoblin.util import Pagination -from pymongo import ASCENDING, DESCENDING from mediagoblin.decorators import uses_pagination diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 5f5c59fb..b05aad1d 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -21,7 +21,7 @@ import smtplib import sys import re import jinja2 -import mongokit +from mediagoblin.db.util import ObjectId import translitcodec from mediagoblin import globals as mgoblin_globals @@ -88,7 +88,7 @@ def setup_user_in_request(request): user = None user = request.app.db.User.one( - {'_id': mongokit.ObjectId(request.session['user_id'])}) + {'_id': ObjectId(request.session['user_id'])}) if not user: # Something's wrong... this user doesn't exist? Invalidate diff --git a/mediagoblin/views.py b/mediagoblin/views.py index 602f1098..dd722c63 100644 --- a/mediagoblin/views.py +++ b/mediagoblin/views.py @@ -14,14 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import datetime - -from webob import Response, exc -import wtforms -from pymongo import DESCENDING -from mongokit import ObjectId -from mediagoblin import models -import gettext +from webob import Response +from mediagoblin.db.util import DESCENDING def root_view(request): media_entries = request.db.MediaEntry.find( |