From 31a8ff428869614db3cae06ab24dbdb1e3d98064 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 17 Jul 2010 11:33:08 -0500 Subject: Initial mediagoblin structure --- mediagoblin/app.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 mediagoblin/app.py (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py new file mode 100644 index 00000000..41ab7f20 --- /dev/null +++ b/mediagoblin/app.py @@ -0,0 +1,64 @@ +import sys +import urllib + +from webob import Request, exc +import routes + +from mediagoblin import routing, util + + +class Error(Exception): pass +class ImproperlyConfigured(Error): pass + + +def load_controller(string): + module_name, func_name = string.split(':', 1) + __import__(module_name) + module = sys.modules[module_name] + func = getattr(module, func_name) + return func + + +class MediagoblinApp(object): + """ + Really basic wsgi app using routes and WebOb. + """ + def __init__(self, user_template_path=None): + self.template_env = util.get_jinja_env(user_template_path) + + def __call__(self, environ, start_response): + request = Request(environ) + path_info = request.path_info + route_match = routing.mapping.match(path_info) + + # No matching page? + if route_match is None: + # Try to do see if we have a match with a trailing slash + # added and if so, redirect + if not path_info.endswith('/') \ + and request.method == 'GET' \ + and routing.mapping.match(path_info + '/'): + new_path_info = path_info + '/' + if request.GET: + new_path_info = '%s?%s' % ( + new_path_info, urllib.urlencode(request.GET)) + redirect = exc.HTTPTemporaryRedirect(location=new_path_info) + return request.get_response(redirect)(environ, start_response) + + # Okay, no matches. 404 time! + return exc.HTTPNotFound()(environ, start_response) + + controller = load_controller(route_match['controller']) + request.start_response = start_response + + request.matchdict = route_match + request.app = self + request.template_env = self.template_env + request.urlgen = routes.URLGenerator(routing.mapping, environ) + + return controller(request)(environ, start_response) + + +def paste_app_factory(global_config, **kw): + return MediagoblinApp( + user_template_path=kw.get('local_templates')) -- cgit v1.2.3 From 73e0dbcca32ed18c0ab63cfde8b34cd112b9e528 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 17 Jul 2010 13:32:57 -0500 Subject: Basic but useless connection to the database --- mediagoblin/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 41ab7f20..4095acc2 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -3,6 +3,7 @@ import urllib from webob import Request, exc import routes +import pymongo from mediagoblin import routing, util @@ -23,8 +24,9 @@ class MediagoblinApp(object): """ Really basic wsgi app using routes and WebOb. """ - def __init__(self, user_template_path=None): + def __init__(self, database, user_template_path=None): self.template_env = util.get_jinja_env(user_template_path) + self.db = database def __call__(self, environ, start_response): request = Request(environ) @@ -60,5 +62,9 @@ class MediagoblinApp(object): def paste_app_factory(global_config, **kw): + connection = pymongo.Connection() + db = kw.get('db_name', 'mediagoblin') + return MediagoblinApp( + db, user_template_path=kw.get('local_templates')) -- cgit v1.2.3 From 0f63a9440d440aac04042bd6125c70a2cb8116d7 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 18 Jul 2010 11:20:18 -0500 Subject: A few adustments to the routing and etc --- mediagoblin/app.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 4095acc2..7231b786 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -27,11 +27,12 @@ class MediagoblinApp(object): def __init__(self, database, user_template_path=None): self.template_env = util.get_jinja_env(user_template_path) self.db = database + self.routing = routing.get_mapper() def __call__(self, environ, start_response): request = Request(environ) path_info = request.path_info - route_match = routing.mapping.match(path_info) + route_match = self.routing.match(path_info) # No matching page? if route_match is None: @@ -39,7 +40,7 @@ class MediagoblinApp(object): # added and if so, redirect if not path_info.endswith('/') \ and request.method == 'GET' \ - and routing.mapping.match(path_info + '/'): + and self.routing.match(path_info + '/'): new_path_info = path_info + '/' if request.GET: new_path_info = '%s?%s' % ( @@ -56,7 +57,7 @@ class MediagoblinApp(object): request.matchdict = route_match request.app = self request.template_env = self.template_env - request.urlgen = routes.URLGenerator(routing.mapping, environ) + request.urlgen = routes.URLGenerator(self.routing, environ) return controller(request)(environ, start_response) -- cgit v1.2.3 From bda3405342feb7f239ccaa2e7cebe76a48909309 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 18 Jul 2010 15:21:51 -0500 Subject: Still totally useless but at least it writes to the database --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 7231b786..ef4feae3 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -64,7 +64,7 @@ class MediagoblinApp(object): def paste_app_factory(global_config, **kw): connection = pymongo.Connection() - db = kw.get('db_name', 'mediagoblin') + db = connection[kw.get('db_name', 'mediagoblin')] return MediagoblinApp( db, -- cgit v1.2.3 From b61874b245a082ae77deef4b0948ddbfeed5a8b0 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 18 Jul 2010 15:59:23 -0500 Subject: Added session support w/ beaker --- mediagoblin/app.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ef4feae3..f688b989 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -1,9 +1,10 @@ import sys import urllib -from webob import Request, exc +from beaker.middleware import SessionMiddleware import routes import pymongo +from webob import Request, exc from mediagoblin import routing, util @@ -58,6 +59,7 @@ class MediagoblinApp(object): request.app = self request.template_env = self.template_env request.urlgen = routes.URLGenerator(self.routing, environ) + request.session = request.environ['beaker.session'] return controller(request)(environ, start_response) @@ -66,6 +68,11 @@ def paste_app_factory(global_config, **kw): connection = pymongo.Connection() db = connection[kw.get('db_name', 'mediagoblin')] - return MediagoblinApp( - db, - user_template_path=kw.get('local_templates')) + mgoblin_app = MediagoblinApp( + db, user_template_path=kw.get('local_templates')) + beakered_app = SessionMiddleware( + mgoblin_app, + {'session.type': 'file', + 'session.cookie_expires': True}) + + return beakered_app -- cgit v1.2.3 From c4d71564761aa5490bc911585bb5021be8c90b54 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 18 Jul 2010 17:59:40 -0500 Subject: beakered_app removed from the paste_app_factory. Deployers should wrap the app w/ beaker themselves --- mediagoblin/app.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index f688b989..1ae01686 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -70,9 +70,5 @@ def paste_app_factory(global_config, **kw): mgoblin_app = MediagoblinApp( db, user_template_path=kw.get('local_templates')) - beakered_app = SessionMiddleware( - mgoblin_app, - {'session.type': 'file', - 'session.cookie_expires': True}) - return beakered_app + return mgoblin_app -- cgit v1.2.3 From 7846e40608be39369c43934646d120f4f79ebd17 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 24 Mar 2011 19:06:31 -0500 Subject: Commenting out beaker till we start using it :) --- mediagoblin/app.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 1ae01686..98f8bc1d 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -59,7 +59,10 @@ class MediagoblinApp(object): request.app = self request.template_env = self.template_env request.urlgen = routes.URLGenerator(self.routing, environ) - request.session = request.environ['beaker.session'] + + # Do we really want to load this via middleware? Maybe? + # let's comment it out till we start using it :) + #request.session = request.environ['beaker.session'] return controller(request)(environ, start_response) -- cgit v1.2.3 From 2b4e236ac34a2d11dde748d514b31428f9a0fa2b Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 26 Mar 2011 13:03:32 -0500 Subject: Properly load in the database and register the connection with the models --- mediagoblin/app.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 98f8bc1d..992d641b 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -3,10 +3,10 @@ import urllib from beaker.middleware import SessionMiddleware import routes -import pymongo +import mongokit from webob import Request, exc -from mediagoblin import routing, util +from mediagoblin import routing, util, models class Error(Exception): pass @@ -25,11 +25,14 @@ class MediagoblinApp(object): """ Really basic wsgi app using routes and WebOb. """ - def __init__(self, database, user_template_path=None): + def __init__(self, connection, database_path, user_template_path=None): self.template_env = util.get_jinja_env(user_template_path) - self.db = database + self.connection = connection + self.db = connection['database_path'] self.routing = routing.get_mapper() + models.register_models(connection) + def __call__(self, environ, start_response): request = Request(environ) path_info = request.path_info @@ -59,6 +62,7 @@ class MediagoblinApp(object): request.app = self request.template_env = self.template_env request.urlgen = routes.URLGenerator(self.routing, environ) + request.db = self.db # Do we really want to load this via middleware? Maybe? # let's comment it out till we start using it :) @@ -68,10 +72,11 @@ class MediagoblinApp(object): def paste_app_factory(global_config, **kw): - connection = pymongo.Connection() - db = connection[kw.get('db_name', 'mediagoblin')] + connection = mongokit.Connection( + kw.get('db_host'), kw.get('db_port')) mgoblin_app = MediagoblinApp( - db, user_template_path=kw.get('local_templates')) + connection, kw.get('db_name', 'mediagoblin'), + user_template_path=kw.get('local_templates')) return mgoblin_app -- cgit v1.2.3 From 65d7374c3752105c66ba8d55fa0943ad66c47b0e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 27 Mar 2011 17:30:42 -0500 Subject: erp, connection[database_path] not connection['database_path'] obviously :P --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 992d641b..478b25d6 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -28,7 +28,7 @@ class MediagoblinApp(object): def __init__(self, connection, database_path, user_template_path=None): self.template_env = util.get_jinja_env(user_template_path) self.connection = connection - self.db = connection['database_path'] + self.db = connection[database_path] self.routing = routing.get_mapper() models.register_models(connection) -- cgit v1.2.3 From e5572c607726599ccbf66a40194b96d12584f38f Mon Sep 17 00:00:00 2001 From: Matt Lee Date: Sun, 27 Mar 2011 18:47:23 -0400 Subject: Added copyright notices --- mediagoblin/app.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 478b25d6..632a0c25 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -1,3 +1,19 @@ +# 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 . + import sys import urllib -- cgit v1.2.3 From 14ba9383de2ff03f2af9bf0595c7b8f1fd43ac7a Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 3 Apr 2011 16:37:36 -0500 Subject: Use beaker from middleware, it's official. --- mediagoblin/app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 632a0c25..cc8cec31 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -81,8 +81,7 @@ class MediagoblinApp(object): request.db = self.db # Do we really want to load this via middleware? Maybe? - # let's comment it out till we start using it :) - #request.session = request.environ['beaker.session'] + request.session = request.environ['beaker.session'] return controller(request)(environ, start_response) -- cgit v1.2.3 From a3fdcf5ce0fafe3ad50429a9a0870a40717ccb75 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 3 Apr 2011 18:40:01 -0500 Subject: This should allow for request.user and show users logged in ... except it's not working? --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index cc8cec31..a9ae223c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -79,9 +79,9 @@ class MediagoblinApp(object): request.template_env = self.template_env request.urlgen = routes.URLGenerator(self.routing, environ) request.db = self.db - # Do we really want to load this via middleware? Maybe? request.session = request.environ['beaker.session'] + util.setup_user_in_request(request) return controller(request)(environ, start_response) -- cgit v1.2.3 From 8e1e744d27fbc887c6d9ce6e937848a25275ed6c Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Wed, 13 Apr 2011 10:04:30 -0400 Subject: Changes Mediagoblin -> MediaGoblin. --- mediagoblin/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index a9ae223c..195d4792 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -1,4 +1,4 @@ -# GNU Mediagoblin -- federated, autonomous media hosting +# 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 @@ -37,7 +37,7 @@ def load_controller(string): return func -class MediagoblinApp(object): +class MediaGoblinApp(object): """ Really basic wsgi app using routes and WebOb. """ @@ -90,7 +90,7 @@ def paste_app_factory(global_config, **kw): connection = mongokit.Connection( kw.get('db_host'), kw.get('db_port')) - mgoblin_app = MediagoblinApp( + mgoblin_app = MediaGoblinApp( connection, kw.get('db_name', 'mediagoblin'), user_template_path=kw.get('local_templates')) -- cgit v1.2.3 From cb8ea0fe3f44f21c13e16f8d6363f56f31c52b27 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 17 Apr 2011 09:43:03 -0500 Subject: Moved app.load_controller -> util.import_component and added tests. --- mediagoblin/app.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 195d4792..0316b43c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -14,10 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import sys import urllib -from beaker.middleware import SessionMiddleware import routes import mongokit from webob import Request, exc @@ -29,14 +27,6 @@ class Error(Exception): pass class ImproperlyConfigured(Error): pass -def load_controller(string): - module_name, func_name = string.split(':', 1) - __import__(module_name) - module = sys.modules[module_name] - func = getattr(module, func_name) - return func - - class MediaGoblinApp(object): """ Really basic wsgi app using routes and WebOb. @@ -71,7 +61,7 @@ class MediaGoblinApp(object): # Okay, no matches. 404 time! return exc.HTTPNotFound()(environ, start_response) - controller = load_controller(route_match['controller']) + controller = util.import_component(route_match['controller']) request.start_response = start_response request.matchdict = route_match @@ -87,9 +77,13 @@ class MediaGoblinApp(object): def paste_app_factory(global_config, **kw): + # Get the database connection connection = mongokit.Connection( kw.get('db_host'), kw.get('db_port')) + # Set up the storage systems. + ## TODO: allow for extra storage systems that aren't just + ## BasicFileStorage. mgoblin_app = MediaGoblinApp( connection, kw.get('db_name', 'mediagoblin'), user_template_path=kw.get('local_templates')) -- cgit v1.2.3 From 5afdd7a1de50fcf31a7e051929f311f3da8332b2 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 17 Apr 2011 10:36:46 -0500 Subject: Actually set up the storage systems --- mediagoblin/app.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 0316b43c..1aab1efb 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -20,7 +20,7 @@ import routes import mongokit from webob import Request, exc -from mediagoblin import routing, util, models +from mediagoblin import routing, util, models, storage class Error(Exception): pass @@ -31,13 +31,24 @@ class MediaGoblinApp(object): """ Really basic wsgi app using routes and WebOb. """ - def __init__(self, connection, database_path, user_template_path=None): + def __init__(self, connection, database_path, + public_store, queue_store, + user_template_path=None): + # Get the template environment self.template_env = util.get_jinja_env(user_template_path) + + # Set up storage systems + self.public_store = public_store + self.queue_store = queue_store + + # Set up database self.connection = connection self.db = connection[database_path] + models.register_models(connection) + + # set up routing self.routing = routing.get_mapper() - models.register_models(connection) def __call__(self, environ, start_response): request = Request(environ) @@ -82,10 +93,14 @@ def paste_app_factory(global_config, **kw): kw.get('db_host'), kw.get('db_port')) # Set up the storage systems. - ## TODO: allow for extra storage systems that aren't just - ## BasicFileStorage. + public_store = storage.storage_system_from_paste_config( + kw, 'publicstore') + queue_store = storage.storage_system_from_paste_config( + kw, 'queuestore') + mgoblin_app = MediaGoblinApp( connection, kw.get('db_name', 'mediagoblin'), + public_store=public_store, queue_store=queue_store, user_template_path=kw.get('local_templates')) return mgoblin_app -- cgit v1.2.3 From 582c4d5fb21f8584314d1ff6a81931e467ec7a04 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 17 Apr 2011 16:30:51 -0500 Subject: Add the staticdirector stuff to the mediagoblin wsgi app. --- mediagoblin/app.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 1aab1efb..5171da99 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -20,7 +20,7 @@ import routes import mongokit from webob import Request, exc -from mediagoblin import routing, util, models, storage +from mediagoblin import routing, util, models, storage, staticdirect class Error(Exception): pass @@ -33,6 +33,7 @@ class MediaGoblinApp(object): """ def __init__(self, connection, database_path, public_store, queue_store, + staticdirector, user_template_path=None): # Get the template environment self.template_env = util.get_jinja_env(user_template_path) @@ -49,10 +50,14 @@ class MediaGoblinApp(object): # set up routing self.routing = routing.get_mapper() + # set up staticdirector tool + self.staticdirector = staticdirector def __call__(self, environ, start_response): request = Request(environ) path_info = request.path_info + + ## Routing / controller loading stuff route_match = self.routing.match(path_info) # No matching page? @@ -75,11 +80,13 @@ class MediaGoblinApp(object): controller = util.import_component(route_match['controller']) request.start_response = start_response + ## Attach utilities to the request object request.matchdict = route_match request.app = self request.template_env = self.template_env request.urlgen = routes.URLGenerator(self.routing, environ) request.db = self.db + request.staticdirect = self.staticdirector # Do we really want to load this via middleware? Maybe? request.session = request.environ['beaker.session'] util.setup_user_in_request(request) @@ -98,9 +105,22 @@ def paste_app_factory(global_config, **kw): queue_store = storage.storage_system_from_paste_config( kw, 'queuestore') + # Set up the staticdirect system + if kw.has_key('direct_remote_path'): + staticdirector = staticdirect.RemoteStaticDirect( + kw['direct_remote_path'].strip()) + elif kw.has_key('direct_remote_paths'): + staticdirector = staticdirect.MultiRemoteStaticDirect( + dict([line.strip().split(' ', 1) + for line in kw['direct_remote_paths'].strip().splitlines()])) + else: + raise ImproperlyConfigured( + "One of direct_remote_path or direct_remote_paths must be provided") + mgoblin_app = MediaGoblinApp( connection, kw.get('db_name', 'mediagoblin'), public_store=public_store, queue_store=queue_store, + staticdirector=staticdirector, user_template_path=kw.get('local_templates')) return mgoblin_app -- cgit v1.2.3 From 0dd659459654dcaa683170e032ba493ab793d016 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 17 Apr 2011 16:36:01 -0500 Subject: Move the request.app stuff to the same area --- mediagoblin/app.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 5171da99..0157748c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -82,14 +82,16 @@ class MediaGoblinApp(object): ## Attach utilities to the request object request.matchdict = route_match - request.app = self - request.template_env = self.template_env request.urlgen = routes.URLGenerator(self.routing, environ) - request.db = self.db - request.staticdirect = self.staticdirector # Do we really want to load this via middleware? Maybe? request.session = request.environ['beaker.session'] util.setup_user_in_request(request) + # Attach self as request.app + # Also attach a few utilities from request.app for convenience? + request.app = self + request.template_env = self.template_env + request.db = self.db + request.staticdirect = self.staticdirector return controller(request)(environ, start_response) -- cgit v1.2.3 From ddff7cce3e480f938d4d69b8d9e55e8dcf4bd562 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 19 Apr 2011 19:16:56 -0500 Subject: util.setup_user_in_request must be called last --- mediagoblin/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 0157748c..ae6db8f7 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -85,7 +85,6 @@ class MediaGoblinApp(object): request.urlgen = routes.URLGenerator(self.routing, environ) # Do we really want to load this via middleware? Maybe? request.session = request.environ['beaker.session'] - util.setup_user_in_request(request) # Attach self as request.app # Also attach a few utilities from request.app for convenience? request.app = self @@ -93,6 +92,8 @@ class MediaGoblinApp(object): request.db = self.db request.staticdirect = self.staticdirector + util.setup_user_in_request(request) + return controller(request)(environ, start_response) -- cgit v1.2.3 From df9809c2098d18b0272c40154b5e40d67b703214 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 24 Apr 2011 14:48:55 -0500 Subject: Make certain bits of info accessable as global variables from anywhere --- mediagoblin/app.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ae6db8f7..78ad19a4 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,6 +21,7 @@ import mongokit from webob import Request, exc from mediagoblin import routing, util, models, storage, staticdirect +from mediagoblin.globals import setup_globals class Error(Exception): pass @@ -53,6 +54,15 @@ class MediaGoblinApp(object): # set up staticdirector tool self.staticdirector = staticdirector + # certain properties need to be accessed globally eg from + # validators, etc, which might not access to the request + # object. + setup_globals( + db_connection=connection, + database=self.db, + public_store=self.public_store, + queue_store=self.queue_store) + def __call__(self, environ, start_response): request = Request(environ) path_info = request.path_info -- cgit v1.2.3 From 5784c4e963b12e0b866ba806f8d2e5c045780d45 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 24 Apr 2011 20:57:38 -0500 Subject: Actually call setup_celery_from_config when launching from paste. Also changed **kw to **app_config, which is more useful of a variable name. --- mediagoblin/app.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 78ad19a4..3ea405e9 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -22,6 +22,7 @@ from webob import Request, exc from mediagoblin import routing, util, models, storage, staticdirect from mediagoblin.globals import setup_globals +from mediagoblin.celery_setup import setup_celery_from_config class Error(Exception): pass @@ -107,33 +108,37 @@ class MediaGoblinApp(object): return controller(request)(environ, start_response) -def paste_app_factory(global_config, **kw): +def paste_app_factory(global_config, **app_config): # Get the database connection connection = mongokit.Connection( - kw.get('db_host'), kw.get('db_port')) + app_config.get('db_host'), app_config.get('db_port')) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( - kw, 'publicstore') + app_config, 'publicstore') queue_store = storage.storage_system_from_paste_config( - kw, 'queuestore') + app_config, 'queuestore') # Set up the staticdirect system - if kw.has_key('direct_remote_path'): + if app_config.has_key('direct_remote_path'): staticdirector = staticdirect.RemoteStaticDirect( - kw['direct_remote_path'].strip()) - elif kw.has_key('direct_remote_paths'): + app_config['direct_remote_path'].strip()) + elif app_config.has_key('direct_remote_paths'): + direct_remote_path_lines = app_config[ + 'direct_remote_paths'].strip().splitlines() staticdirector = staticdirect.MultiRemoteStaticDirect( dict([line.strip().split(' ', 1) - for line in kw['direct_remote_paths'].strip().splitlines()])) + for line in direct_remote_path_lines])) else: raise ImproperlyConfigured( "One of direct_remote_path or direct_remote_paths must be provided") + setup_celery_from_config(app_config, global_config) + mgoblin_app = MediaGoblinApp( - connection, kw.get('db_name', 'mediagoblin'), + connection, app_config.get('db_name', 'mediagoblin'), public_store=public_store, queue_store=queue_store, staticdirector=staticdirector, - user_template_path=kw.get('local_templates')) + user_template_path=app_config.get('local_templates')) return mgoblin_app -- cgit v1.2.3 From 1bb0fdf2f4f568019c3449f269c69f406507bd7c Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 26 Apr 2011 15:46:56 -0500 Subject: HTTPFound more accurate than HTTPMovedPermanently. (Just observed this in cc.engine, making observation here also while I'm at it :)) --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 3ea405e9..59b943dd 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -82,7 +82,7 @@ class MediaGoblinApp(object): if request.GET: new_path_info = '%s?%s' % ( new_path_info, urllib.urlencode(request.GET)) - redirect = exc.HTTPTemporaryRedirect(location=new_path_info) + redirect = exc.HTTPFound(location=new_path_info) return request.get_response(redirect)(environ, start_response) # Okay, no matches. 404 time! -- cgit v1.2.3 From 4c093e85c7457e989b22b5274f240e3ccfdab210 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 8 May 2011 00:55:57 +0200 Subject: Made changes according to http://bugs.foocorp.net/issues/271#note-7 Signed-off-by: Joar Wandborg --- mediagoblin/app.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 59b943dd..ca3de6ca 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -36,6 +36,7 @@ class MediaGoblinApp(object): def __init__(self, connection, database_path, public_store, queue_store, staticdirector, + email_sender_address, user_template_path=None): # Get the template environment self.template_env = util.get_jinja_env(user_template_path) @@ -59,6 +60,7 @@ class MediaGoblinApp(object): # validators, etc, which might not access to the request # object. setup_globals( + email_sender_address=email_sender_address, db_connection=connection, database=self.db, public_store=self.public_store, @@ -139,6 +141,8 @@ def paste_app_factory(global_config, **app_config): connection, app_config.get('db_name', 'mediagoblin'), public_store=public_store, queue_store=queue_store, staticdirector=staticdirector, + email_sender_address=app_config.get('email_sender_address', + 'notice@medigoblin.org'), user_template_path=app_config.get('local_templates')) return mgoblin_app -- cgit v1.2.3 From 8a6a81bcaa557f1d7ceebea8b372be7cc3423ca2 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 8 May 2011 02:03:11 +0200 Subject: Updated default sender address Signed-off-by: Joar Wandborg --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ca3de6ca..ad9e77df 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -142,7 +142,7 @@ def paste_app_factory(global_config, **app_config): public_store=public_store, queue_store=queue_store, staticdirector=staticdirector, email_sender_address=app_config.get('email_sender_address', - 'notice@medigoblin.org'), + 'notice@mediagoblin.example.org'), user_template_path=app_config.get('local_templates')) return mgoblin_app -- cgit v1.2.3 From 29f3fb7052a0a512d5970a936b30175b9c7eef63 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 7 May 2011 22:45:06 -0500 Subject: Added an email debug mode which, by default, is enabled --- mediagoblin/app.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ad9e77df..e93e0c4e 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -18,6 +18,7 @@ import urllib import routes import mongokit +from paste.deploy.converters import asbool from webob import Request, exc from mediagoblin import routing, util, models, storage, staticdirect @@ -36,7 +37,7 @@ class MediaGoblinApp(object): def __init__(self, connection, database_path, public_store, queue_store, staticdirector, - email_sender_address, + email_sender_address, email_debug_mode, user_template_path=None): # Get the template environment self.template_env = util.get_jinja_env(user_template_path) @@ -61,6 +62,7 @@ class MediaGoblinApp(object): # object. setup_globals( email_sender_address=email_sender_address, + email_debug_mode=email_debug_mode, db_connection=connection, database=self.db, public_store=self.public_store, @@ -141,8 +143,9 @@ def paste_app_factory(global_config, **app_config): connection, app_config.get('db_name', 'mediagoblin'), public_store=public_store, queue_store=queue_store, staticdirector=staticdirector, - email_sender_address=app_config.get('email_sender_address', - 'notice@mediagoblin.example.org'), + email_sender_address=app_config.get( + 'email_sender_address', 'notice@mediagoblin.example.org'), + email_debug_mode=app_config.get('email_debug_mode'), user_template_path=app_config.get('local_templates')) return mgoblin_app -- cgit v1.2.3 From 19f8a24e4187b81f18a0def87b2b170a40977ff1 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Sun, 8 May 2011 11:12:38 +0200 Subject: app.py: Need to pass in port number as 'int' When we configured an explicite db_port in mediagoblin.ini, paster would crash claiming that the port number must be an int. Given that we don't have a "get_conf_int()" function or something similar (yet?), simply convert the port number to int before passing it to the mongo Connection instance. Signed-off-by: Sebastian Spaeth --- mediagoblin/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index e93e0c4e..5c094f38 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -114,8 +114,9 @@ class MediaGoblinApp(object): def paste_app_factory(global_config, **app_config): # Get the database connection + port = int(app_config.get('db_port')) connection = mongokit.Connection( - app_config.get('db_host'), app_config.get('db_port')) + app_config.get('db_host'), port) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( -- cgit v1.2.3 From a1eb1f6051300e5d3ce9d1f32d28a25a567e73d8 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 8 May 2011 07:16:50 -0500 Subject: Only convert db port if it's there and use asint to do it (better errors if failing) --- mediagoblin/app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 5c094f38..913e530e 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -18,7 +18,7 @@ import urllib import routes import mongokit -from paste.deploy.converters import asbool +from paste.deploy.converters import asint from webob import Request, exc from mediagoblin import routing, util, models, storage, staticdirect @@ -114,7 +114,9 @@ class MediaGoblinApp(object): def paste_app_factory(global_config, **app_config): # Get the database connection - port = int(app_config.get('db_port')) + port = app_config.get('db_port') + if port: + port = asint(port) connection = mongokit.Connection( app_config.get('db_host'), port) -- cgit v1.2.3 From cd847fd346e048a4bd6c42e065475b3167991213 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 8 May 2011 10:07:39 -0500 Subject: Asbool the email debug mode option --- mediagoblin/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 913e530e..2a2f21cc 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -18,7 +18,7 @@ import urllib import routes import mongokit -from paste.deploy.converters import asint +from paste.deploy.converters import asbool, asint from webob import Request, exc from mediagoblin import routing, util, models, storage, staticdirect @@ -148,7 +148,7 @@ def paste_app_factory(global_config, **app_config): staticdirector=staticdirector, email_sender_address=app_config.get( 'email_sender_address', 'notice@mediagoblin.example.org'), - email_debug_mode=app_config.get('email_debug_mode'), + email_debug_mode=asbool(app_config.get('email_debug_mode')), user_template_path=app_config.get('local_templates')) return mgoblin_app -- cgit v1.2.3 From 0e0e3d9aadd481353c9a4a44b37dcb68c1efbaab Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 12 May 2011 15:17:07 -0500 Subject: Separation between setting up the template env and the template loader for a glorious future where we have gettext in template context --- mediagoblin/app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 2a2f21cc..d124558d 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -40,7 +40,7 @@ class MediaGoblinApp(object): email_sender_address, email_debug_mode, user_template_path=None): # Get the template environment - self.template_env = util.get_jinja_env(user_template_path) + self.template_loader = util.get_jinja_loader(user_template_path) # Set up storage systems self.public_store = public_store @@ -103,7 +103,10 @@ class MediaGoblinApp(object): # Attach self as request.app # Also attach a few utilities from request.app for convenience? request.app = self - request.template_env = self.template_env + request.locale = util.get_locale_from_request(request) + + request.template_env = util.get_jinja_env( + self.template_loader, request.locale) request.db = self.db request.staticdirect = self.staticdirector -- cgit v1.2.3 From 0f18ed8f5e179326721221df93734864074bc185 Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 18 May 2011 00:44:10 +0200 Subject: Move models into new db/ directory The database is a central point of interest/discussion. Represent that by its own directory. This will surely become more interesting when we have migrations for example. --- mediagoblin/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index d124558d..908bb19c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,7 +21,8 @@ import mongokit from paste.deploy.converters import asbool, asint from webob import Request, exc -from mediagoblin import routing, util, models, storage, staticdirect +from mediagoblin import routing, util, storage, staticdirect +from mediagoblin.db import models from mediagoblin.globals import setup_globals from mediagoblin.celery_setup import setup_celery_from_config -- cgit v1.2.3 From a4bae8700e2186adb91d5c0a5198e7a8923143c6 Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 18 May 2011 01:03:40 +0200 Subject: Move "connect to database" into db/util.py --- mediagoblin/app.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'mediagoblin/app.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( -- cgit v1.2.3 From 3262ad1dbbc1919de2393e11900f5a47ac5dcd75 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 18 May 2011 08:44:57 -0500 Subject: Renaming connect_database to connect_database_from_config and using in from_celery --- mediagoblin/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index c94b5f6d..60adba56 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -22,7 +22,7 @@ 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.db.util import connect_database_from_config from mediagoblin.globals import setup_globals from mediagoblin.celery_setup import setup_celery_from_config @@ -118,7 +118,7 @@ class MediaGoblinApp(object): def paste_app_factory(global_config, **app_config): # Get the database connection - connection = connect_database(app_config) + connection = connect_database_from_config(app_config) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( -- cgit v1.2.3 From 86f9b473877434e5a811d057e192c91a70d67ef5 Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 18 May 2011 22:03:52 +0200 Subject: Clean unused imports (found by pyflakes). --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 60adba56..25a6f541 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -17,7 +17,7 @@ import urllib import routes -from paste.deploy.converters import asbool, asint +from paste.deploy.converters import asbool from webob import Request, exc from mediagoblin import routing, util, storage, staticdirect -- cgit v1.2.3 From a67fec8177c09c4e74ce7f4301b88f4e7ea6e658 Mon Sep 17 00:00:00 2001 From: Elrond Date: Thu, 19 May 2011 01:35:02 +0200 Subject: Factor out most of the database connection into db/open.py I needed to split the db connection/opening into open.py, due to an import loop: - util.py needs db/util.py:ObjectId - db/util.py would need db/models.py - db/models.py needs util.py:slugify --- mediagoblin/app.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 25a6f541..640ffc45 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,8 +21,7 @@ from paste.deploy.converters import asbool 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_config +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 @@ -35,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, @@ -49,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() @@ -118,7 +116,7 @@ class MediaGoblinApp(object): def paste_app_factory(global_config, **app_config): # Get the database connection - connection = connect_database_from_config(app_config) + connection, db = setup_connection_and_db_from_config(app_config) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( @@ -143,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( -- cgit v1.2.3 From 571198c938d66d2cc4d7d7a0d261633d51061968 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 20 May 2011 18:49:04 -0500 Subject: Now you can set CELERY_ALWAYS_EAGER environment variable so that you don't have to run celeryd at the same time. This should make Elrond happy ;) --- mediagoblin/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 640ffc45..714404de 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import os import urllib import routes @@ -138,7 +139,12 @@ def paste_app_factory(global_config, **app_config): raise ImproperlyConfigured( "One of direct_remote_path or direct_remote_paths must be provided") - setup_celery_from_config(app_config, global_config) + if asbool(os.environ.get('CELERY_ALWAYS_EAGER')): + setup_celery_from_config( + app_config, global_config, + force_celery_always_eager=True) + else: + setup_celery_from_config(app_config, global_config) mgoblin_app = MediaGoblinApp( connection, db, -- cgit v1.2.3 From c5678c1ab3deb3f7a2961225c35260d5bbd69604 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 4 Jun 2011 13:20:48 -0500 Subject: Proper webtest infrastructure... seems to be about right anyway :) --- mediagoblin/app.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 714404de..e5949531 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -139,12 +139,13 @@ def paste_app_factory(global_config, **app_config): raise ImproperlyConfigured( "One of direct_remote_path or direct_remote_paths must be provided") - if asbool(os.environ.get('CELERY_ALWAYS_EAGER')): - setup_celery_from_config( - app_config, global_config, - force_celery_always_eager=True) - else: - setup_celery_from_config(app_config, global_config) + if not asbool(app_config.get('celery_setup_elsewhere')): + if asbool(os.environ.get('CELERY_ALWAYS_EAGER')): + setup_celery_from_config( + app_config, global_config, + force_celery_always_eager=True) + else: + setup_celery_from_config(app_config, global_config) mgoblin_app = MediaGoblinApp( connection, db, -- cgit v1.2.3 From 7ecc58cc5cf49c87001c38ba5d0607644ca195d4 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 11 Jun 2011 19:47:02 -0500 Subject: Have the application set up instances of the WorkbenchManager. --- mediagoblin/app.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index e5949531..da2b7d35 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -25,6 +25,8 @@ 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 +from mediagoblin.process_media.workbench import ( + WorkbenchManager, DEFAULT_WORKBENCH_DIR) class Error(Exception): pass @@ -39,7 +41,8 @@ class MediaGoblinApp(object): public_store, queue_store, staticdirector, email_sender_address, email_debug_mode, - user_template_path=None): + user_template_path=None, + workbench_path=DEFAULT_WORKBENCH_DIR): # Get the template environment self.template_loader = util.get_jinja_loader(user_template_path) @@ -66,7 +69,8 @@ class MediaGoblinApp(object): db_connection=connection, database=self.db, public_store=self.public_store, - queue_store=self.queue_store) + queue_store=self.queue_store, + workbench_manager=WorkbenchManager(workbench_path)) def __call__(self, environ, start_response): request = Request(environ) @@ -154,6 +158,7 @@ def paste_app_factory(global_config, **app_config): email_sender_address=app_config.get( 'email_sender_address', 'notice@mediagoblin.example.org'), email_debug_mode=asbool(app_config.get('email_debug_mode')), - user_template_path=app_config.get('local_templates')) + user_template_path=app_config.get('local_templates'), + workbench_path=app_config.get('workbench_path', DEFAULT_WORKBENCH_DIR)) return mgoblin_app -- cgit v1.2.3 From a32acafa0bfebfc886a05414b4e33943d358efc7 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 11 Jun 2011 20:33:41 -0500 Subject: Moving workbench out of process_media --- mediagoblin/app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index da2b7d35..5d594039 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -25,8 +25,7 @@ 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 -from mediagoblin.process_media.workbench import ( - WorkbenchManager, DEFAULT_WORKBENCH_DIR) +from mediagoblin.workbench import WorkbenchManager, DEFAULT_WORKBENCH_DIR class Error(Exception): pass -- cgit v1.2.3 From 6e7ce8d1af8c6fcf7d00992b1c8ef0e8c1602479 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 12 Jun 2011 17:27:37 -0500 Subject: mediagoblin.globals->mediagoblin.mg_globals --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 5d594039..a1c6b512 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -23,7 +23,7 @@ from webob import Request, exc 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.mg_globals import setup_globals from mediagoblin.celery_setup import setup_celery_from_config from mediagoblin.workbench import WorkbenchManager, DEFAULT_WORKBENCH_DIR -- cgit v1.2.3 From 3f5cf663c0c8c2c06c9185af82b5f75423fce7f3 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 18 Jun 2011 17:59:38 -0500 Subject: Move entire app structure over to using the new config system. This is a huge change! This means several things. - From the python point of view, launching the application is a heck of a lot cleaner. You just need to pass in the config file path to MediaGoblinApp's __init__() and whether or not this funtion should setup celery and you're good. - There are now two separate config files, separating the server setup from the application setup. - server.ini: the paste deploy config file, which configures the applications and server setup but *NOT* the mediagoblin application itself. - mediagoblin.ini: where you configure mediagoblin (and possibly celery) - Launching the application is now different. Instead of: ./bin/paster serve mediagoblin.ini --reload We launch like: ./bin/paster serve server.ini --reload --- mediagoblin/app.py | 145 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 62 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index a1c6b512..da1aba47 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -18,14 +18,15 @@ import os import urllib import routes -from paste.deploy.converters import asbool from webob import Request, exc from mediagoblin import routing, util, storage, staticdirect +from mediagoblin.config import ( + read_mediagoblin_config, generate_validation_report) from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.mg_globals import setup_globals from mediagoblin.celery_setup import setup_celery_from_config -from mediagoblin.workbench import WorkbenchManager, DEFAULT_WORKBENCH_DIR +from mediagoblin.workbench import WorkbenchManager class Error(Exception): pass @@ -34,42 +35,101 @@ class ImproperlyConfigured(Error): pass class MediaGoblinApp(object): """ - Really basic wsgi app using routes and WebOb. + WSGI application of MediaGoblin + + ... this is the heart of the program! """ - def __init__(self, connection, db, - public_store, queue_store, - staticdirector, - email_sender_address, email_debug_mode, - user_template_path=None, - workbench_path=DEFAULT_WORKBENCH_DIR): + def __init__(self, config_path, setup_celery=True): + """ + Initialize the application based on a configuration file. + + Arguments: + - config_path: path to the configuration file we're opening. + - setup_celery: whether or not to setup celery during init. + (Note: setting 'celery_setup_elsewhere' also disables + setting up celery.) + """ + ############## + # Setup config + ############## + + # Open and setup the config + global_config, validation_result = read_mediagoblin_config(config_path) + app_config = global_config['mediagoblin'] + # report errors if necessary + validation_report = generate_validation_report( + global_config, validation_result) + if validation_report: + raise ImproperlyConfigured(validation_report) + + ########################################## + # Setup other connections / useful objects + ########################################## + + # Set up the database + self.connection, self.db = setup_connection_and_db_from_config( + app_config) + # Get the template environment - self.template_loader = util.get_jinja_loader(user_template_path) + self.template_loader = util.get_jinja_loader( + app_config.get('user_template_path')) # Set up storage systems - self.public_store = public_store - self.queue_store = queue_store - - # Set up database - self.connection = connection - self.db = db + self.public_store = storage.storage_system_from_paste_config( + app_config, 'publicstore') + self.queue_store = storage.storage_system_from_paste_config( + app_config, 'queuestore') # set up routing self.routing = routing.get_mapper() # set up staticdirector tool - self.staticdirector = staticdirector - + if app_config.has_key('direct_remote_path'): + self.staticdirector = staticdirect.RemoteStaticDirect( + app_config['direct_remote_path'].strip()) + elif app_config.has_key('direct_remote_paths'): + direct_remote_path_lines = app_config[ + 'direct_remote_paths'].strip().splitlines() + self.staticdirector = staticdirect.MultiRemoteStaticDirect( + dict([line.strip().split(' ', 1) + for line in direct_remote_path_lines])) + else: + raise ImproperlyConfigured( + "One of direct_remote_path or " + "direct_remote_paths must be provided") + + # Setup celery, if appropriate + if setup_celery and not app_config.get('celery_setup_elsewhere'): + if os.environ.get('CELERY_ALWAYS_EAGER'): + setup_celery_from_config( + app_config, global_config, + force_celery_always_eager=True) + else: + setup_celery_from_config(app_config, global_config) + + ####################################################### + # Insert appropriate things into mediagoblin.mg_globals + # # certain properties need to be accessed globally eg from # validators, etc, which might not access to the request # object. + ####################################################### + setup_globals( - email_sender_address=email_sender_address, - email_debug_mode=email_debug_mode, - db_connection=connection, + app_config=app_config, + global_config=global_config, + + # TODO: No need to set these two up as globals, we could + # just read them out of mg_globals.app_config + email_sender_address=app_config['email_sender_address'], + email_debug_mode=app_config['email_debug_mode'], + + # Actual, useful to everyone objects + db_connection=self.connection, database=self.db, public_store=self.public_store, queue_store=self.queue_store, - workbench_manager=WorkbenchManager(workbench_path)) + workbench_manager=WorkbenchManager(app_config['workbench_path'])) def __call__(self, environ, start_response): request = Request(environ) @@ -119,45 +179,6 @@ class MediaGoblinApp(object): def paste_app_factory(global_config, **app_config): - # Get the database connection - connection, db = setup_connection_and_db_from_config(app_config) - - # Set up the storage systems. - public_store = storage.storage_system_from_paste_config( - app_config, 'publicstore') - queue_store = storage.storage_system_from_paste_config( - app_config, 'queuestore') - - # Set up the staticdirect system - if app_config.has_key('direct_remote_path'): - staticdirector = staticdirect.RemoteStaticDirect( - app_config['direct_remote_path'].strip()) - elif app_config.has_key('direct_remote_paths'): - direct_remote_path_lines = app_config[ - 'direct_remote_paths'].strip().splitlines() - staticdirector = staticdirect.MultiRemoteStaticDirect( - dict([line.strip().split(' ', 1) - for line in direct_remote_path_lines])) - else: - raise ImproperlyConfigured( - "One of direct_remote_path or direct_remote_paths must be provided") - - if not asbool(app_config.get('celery_setup_elsewhere')): - if asbool(os.environ.get('CELERY_ALWAYS_EAGER')): - setup_celery_from_config( - app_config, global_config, - force_celery_always_eager=True) - else: - setup_celery_from_config(app_config, global_config) - - mgoblin_app = MediaGoblinApp( - connection, db, - public_store=public_store, queue_store=queue_store, - staticdirector=staticdirector, - email_sender_address=app_config.get( - 'email_sender_address', 'notice@mediagoblin.example.org'), - email_debug_mode=asbool(app_config.get('email_debug_mode')), - user_template_path=app_config.get('local_templates'), - workbench_path=app_config.get('workbench_path', DEFAULT_WORKBENCH_DIR)) + mgoblin_app = MediaGoblinApp(app_config['config']) return mgoblin_app -- cgit v1.2.3 From becb77ee8cf4cc92d87d656117d6bac96544f168 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 18 Jun 2011 19:00:01 -0500 Subject: It's a good idea for us to pass the application itself into mg_globals :) --- mediagoblin/app.py | 1 + 1 file changed, 1 insertion(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index da1aba47..d2a0695e 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -125,6 +125,7 @@ class MediaGoblinApp(object): email_debug_mode=app_config['email_debug_mode'], # Actual, useful to everyone objects + app=self, db_connection=self.connection, database=self.db, public_store=self.public_store, -- cgit v1.2.3 From 3c7d11ff2840fdc40be8cf916aef1ae7f532c309 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 19 Jun 2011 11:36:52 -0500 Subject: renaming storage_system_from_paste_config()->storage_system_from_config() As Elrond points out, this name doesn't make sense anymore since this isn't based on the paste config. Thanks Elrond! --- mediagoblin/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index d2a0695e..b27b5761 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -75,9 +75,9 @@ class MediaGoblinApp(object): app_config.get('user_template_path')) # Set up storage systems - self.public_store = storage.storage_system_from_paste_config( + self.public_store = storage.storage_system_from_config( app_config, 'publicstore') - self.queue_store = storage.storage_system_from_paste_config( + self.queue_store = storage.storage_system_from_config( app_config, 'queuestore') # set up routing -- cgit v1.2.3 From 073b61fe53d4e499d7034bb8de2404cd87dc9095 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 19 Jun 2011 23:09:35 +0200 Subject: Move mediagoblin.celery_setup -> mediagoblin.init.celery As the first target of the new .init. submodule move celery_setup there. Quite straight forward, just a lot of places to change. --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index b27b5761..080c8e3a 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -25,7 +25,7 @@ from mediagoblin.config import ( read_mediagoblin_config, generate_validation_report) from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.mg_globals import setup_globals -from mediagoblin.celery_setup import setup_celery_from_config +from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.workbench import WorkbenchManager -- cgit v1.2.3 From 42ef819cbb7edb2aecbc39f60ecfbfaee59b5039 Mon Sep 17 00:00:00 2001 From: Elrond Date: Thu, 23 Jun 2011 18:45:39 +0200 Subject: Move get_jinja_loader to init submodule. --- mediagoblin/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 080c8e3a..2450831a 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -26,6 +26,7 @@ from mediagoblin.config import ( from mediagoblin.db.open import setup_connection_and_db_from_config 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 @@ -71,7 +72,7 @@ class MediaGoblinApp(object): app_config) # Get the template environment - self.template_loader = util.get_jinja_loader( + self.template_loader = get_jinja_loader( app_config.get('user_template_path')) # Set up storage systems -- cgit v1.2.3 From 421129b6bbf460057831914c25ab5694f5d21d4f Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 2 Jul 2011 22:40:19 +0200 Subject: Move config.py to init/ Some simple changes needed to do that. The interesting question left: Should config_spec.ini also be moved? --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 2450831a..9454b403 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,7 +21,7 @@ import routes from webob import Request, exc from mediagoblin import routing, util, storage, staticdirect -from mediagoblin.config import ( +from mediagoblin.init.config import ( read_mediagoblin_config, generate_validation_report) from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.mg_globals import setup_globals -- cgit v1.2.3 From c85c9dc712f38af1403572f9367edc692306dc02 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 4 Jul 2011 23:47:13 +0200 Subject: Move setting up of staticdirector to init submodule This duplicates some exceptions, which will be fixed very soon. --- mediagoblin/app.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 9454b403..ab8549cb 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -20,13 +20,13 @@ import urllib import routes from webob import Request, exc -from mediagoblin import routing, util, storage, staticdirect +from mediagoblin import routing, util, storage from mediagoblin.init.config import ( read_mediagoblin_config, generate_validation_report) from mediagoblin.db.open import setup_connection_and_db_from_config 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.init import get_jinja_loader, get_staticdirector from mediagoblin.workbench import WorkbenchManager @@ -85,19 +85,7 @@ class MediaGoblinApp(object): self.routing = routing.get_mapper() # set up staticdirector tool - if app_config.has_key('direct_remote_path'): - self.staticdirector = staticdirect.RemoteStaticDirect( - app_config['direct_remote_path'].strip()) - elif app_config.has_key('direct_remote_paths'): - direct_remote_path_lines = app_config[ - 'direct_remote_paths'].strip().splitlines() - self.staticdirector = staticdirect.MultiRemoteStaticDirect( - dict([line.strip().split(' ', 1) - for line in direct_remote_path_lines])) - else: - raise ImproperlyConfigured( - "One of direct_remote_path or " - "direct_remote_paths must be provided") + self.staticdirector = get_staticdirector(app_config) # Setup celery, if appropriate if setup_celery and not app_config.get('celery_setup_elsewhere'): -- cgit v1.2.3 From fe289be4c85774b1d48f9db1ef644ee88b672e08 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 4 Jul 2011 23:57:45 +0200 Subject: Create setup_global_and_app_config Moving the config reading and error reporting from app.py to init/__init__.py. Straight forward. This also fixes the duplicated exceptions. --- mediagoblin/app.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ab8549cb..0ef670d7 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,19 +21,14 @@ import routes from webob import Request, exc from mediagoblin import routing, util, storage -from mediagoblin.init.config import ( - read_mediagoblin_config, generate_validation_report) from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config -from mediagoblin.init import get_jinja_loader, get_staticdirector +from mediagoblin.init import get_jinja_loader, get_staticdirector, \ + setup_global_and_app_config from mediagoblin.workbench import WorkbenchManager -class Error(Exception): pass -class ImproperlyConfigured(Error): pass - - class MediaGoblinApp(object): """ WSGI application of MediaGoblin @@ -55,13 +50,7 @@ class MediaGoblinApp(object): ############## # Open and setup the config - global_config, validation_result = read_mediagoblin_config(config_path) - app_config = global_config['mediagoblin'] - # report errors if necessary - validation_report = generate_validation_report( - global_config, validation_result) - if validation_report: - raise ImproperlyConfigured(validation_report) + global_config, app_config = setup_global_and_app_config(config_path) ########################################## # Setup other connections / useful objects -- cgit v1.2.3 From cca5d55d40fe5b4f097e015c72cbd8e6c4c3232a Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 5 Jul 2011 00:02:04 +0200 Subject: Let setup_global_and_app_config call setup_globals Let setup_global_and_app_config set the global and app config in the mg_globals already. This way, the config is available to everyone very early. --- mediagoblin/app.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 0ef670d7..6d6346d2 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -94,9 +94,6 @@ class MediaGoblinApp(object): ####################################################### setup_globals( - app_config=app_config, - global_config=global_config, - # TODO: No need to set these two up as globals, we could # just read them out of mg_globals.app_config email_sender_address=app_config['email_sender_address'], -- cgit v1.2.3 From 7664b4db81f1449b37c774cecb4fba4a505ae5d0 Mon Sep 17 00:00:00 2001 From: Elrond Date: Thu, 7 Jul 2011 22:08:20 +0200 Subject: Factor setup_workbench into init submodule. --- mediagoblin/app.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 6d6346d2..c5fcc1dd 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -25,8 +25,7 @@ from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init import get_jinja_loader, get_staticdirector, \ - setup_global_and_app_config -from mediagoblin.workbench import WorkbenchManager + setup_global_and_app_config, setup_workbench class MediaGoblinApp(object): @@ -104,8 +103,8 @@ class MediaGoblinApp(object): db_connection=self.connection, database=self.db, public_store=self.public_store, - queue_store=self.queue_store, - workbench_manager=WorkbenchManager(app_config['workbench_path'])) + queue_store=self.queue_store) + setup_workbench() def __call__(self, environ, start_response): request = Request(environ) -- cgit v1.2.3 From 1fd97db348fb8eb7b455f4f991fe73143611a945 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 9 Jul 2011 17:11:23 -0500 Subject: Added a note about workbench only currently being used by celery --- mediagoblin/app.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index c5fcc1dd..ae39694f 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -104,6 +104,9 @@ class MediaGoblinApp(object): database=self.db, public_store=self.public_store, queue_store=self.queue_store) + + # Workbench *currently* only used by celery, so this only + # matters in always eager mode :) setup_workbench() def __call__(self, environ, start_response): -- cgit v1.2.3 From ff94114c5d19be45a674a36980be643e097f7f12 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 10 Jul 2011 22:50:03 -0500 Subject: Setup the application to record the database version if missing on launch --- mediagoblin/app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 9454b403..523b9302 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -24,6 +24,7 @@ from mediagoblin import routing, util, storage, staticdirect from mediagoblin.init.config import ( read_mediagoblin_config, generate_validation_report) 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 @@ -71,6 +72,16 @@ class MediaGoblinApp(object): self.connection, self.db = setup_connection_and_db_from_config( app_config) + # Init the migration number if necessary + migration_manager = MigrationManager(self.db) + migration_manager.install_migration_version_if_missing() + + # Tiny hack to warn user if our migration is out of date + if not migration_manager.database_at_latest_migration(): + print ( + "*WARNING:* Your migrations are out of date, " + "maybe run ./bin/gmg migrate?") + # Get the template environment self.template_loader = get_jinja_loader( app_config.get('user_template_path')) -- cgit v1.2.3 From 6ae8b541f957b49ae86051814097e769d20f29af Mon Sep 17 00:00:00 2001 From: Deb Date: Tue, 12 Jul 2011 21:21:35 -0400 Subject: removed email variables from globals module --- mediagoblin/app.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ae39694f..147db09c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -93,12 +93,6 @@ class MediaGoblinApp(object): ####################################################### setup_globals( - # TODO: No need to set these two up as globals, we could - # just read them out of mg_globals.app_config - email_sender_address=app_config['email_sender_address'], - email_debug_mode=app_config['email_debug_mode'], - - # Actual, useful to everyone objects app=self, db_connection=self.connection, database=self.db, -- cgit v1.2.3 From 90e342f90ffc59991e040645938521a0a5ba050d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 14 Jul 2011 00:32:01 -0500 Subject: app.py and migrate.py must import migrations in order to load said migrations... --- mediagoblin/app.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 7a6a1f33..1c38f778 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -28,6 +28,9 @@ from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init import get_jinja_loader, get_staticdirector, \ setup_global_and_app_config, setup_workbench +# This MUST be imported so as to set up the appropriate migrations! +from mediagoblin.db import migrations + class MediaGoblinApp(object): """ -- cgit v1.2.3 From 3f4b5e4a4e318360e02b070b4aee2d0b2c01c3d9 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 17 Jul 2011 17:45:50 +0200 Subject: Move application level setup of database to init/ Setting up the database now involves checking the migrations status and setting up the globals. Moved all of that into init/__init__.py:setup_database(). --- mediagoblin/app.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 1c38f778..85c3c0c7 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,15 +21,10 @@ import routes from webob import Request, exc 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, get_staticdirector, \ - setup_global_and_app_config, setup_workbench - -# This MUST be imported so as to set up the appropriate migrations! -from mediagoblin.db import migrations + setup_global_and_app_config, setup_workbench, setup_database class MediaGoblinApp(object): @@ -60,18 +55,7 @@ class MediaGoblinApp(object): ########################################## # Set up the database - self.connection, self.db = setup_connection_and_db_from_config( - app_config) - - # Init the migration number if necessary - migration_manager = MigrationManager(self.db) - migration_manager.install_migration_version_if_missing() - - # Tiny hack to warn user if our migration is out of date - if not migration_manager.database_at_latest_migration(): - print ( - "*WARNING:* Your migrations are out of date, " - "maybe run ./bin/gmg migrate?") + self.connection, self.db = setup_database() # Get the template environment self.template_loader = get_jinja_loader( @@ -108,8 +92,6 @@ class MediaGoblinApp(object): setup_globals( app=self, - db_connection=self.connection, - database=self.db, public_store=self.public_store, queue_store=self.queue_store) -- cgit v1.2.3 From dccef26263ba98c47fc5f8121a074a34b012ba89 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 17 Jul 2011 16:09:22 +0200 Subject: Move setting up of storage into init/__init__.py Factoring out this one should be the last one needed to rewrite the celery setup. The idea is to not setup the whole app, but just call a bunch of individual setup_* functions and be done. --- mediagoblin/app.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 85c3c0c7..58db4e8d 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -20,11 +20,12 @@ import urllib import routes from webob import Request, exc -from mediagoblin import routing, util, storage +from mediagoblin import routing, util from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init import get_jinja_loader, get_staticdirector, \ - setup_global_and_app_config, setup_workbench, setup_database + setup_global_and_app_config, setup_workbench, setup_database, \ + setup_storage class MediaGoblinApp(object): @@ -62,10 +63,7 @@ class MediaGoblinApp(object): app_config.get('user_template_path')) # Set up storage systems - self.public_store = storage.storage_system_from_config( - app_config, 'publicstore') - self.queue_store = storage.storage_system_from_config( - app_config, 'queuestore') + self.public_store, self.queue_store = setup_storage() # set up routing self.routing = routing.get_mapper() @@ -90,10 +88,7 @@ class MediaGoblinApp(object): # object. ####################################################### - setup_globals( - app=self, - public_store=self.public_store, - queue_store=self.queue_store) + setup_globals(app = self) # Workbench *currently* only used by celery, so this only # matters in always eager mode :) -- cgit v1.2.3 From 50854db05d130ef4b564379584d147880fe72a92 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Wed, 27 Jul 2011 16:21:21 -0700 Subject: Tweaks import lines switching \ for ( ). --- mediagoblin/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 58db4e8d..c1ee3d77 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -23,9 +23,9 @@ from webob import Request, exc from mediagoblin import routing, util from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config -from mediagoblin.init import get_jinja_loader, get_staticdirector, \ - setup_global_and_app_config, setup_workbench, setup_database, \ - setup_storage +from mediagoblin.init import (get_jinja_loader, get_staticdirector, + setup_global_and_app_config, setup_workbench, setup_database, + setup_storage) class MediaGoblinApp(object): -- cgit v1.2.3 From 3d0557bf25683c26ec2b6de041d53fe5a0c6255c Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 20 Aug 2011 15:00:25 -0500 Subject: Change the ordering of the app's __call__ method (attach things to request first) This will make it easier for us to call something like a 404 page rendering method before the matching check is done. --- mediagoblin/app.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index c1ee3d77..96a7ad61 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -101,6 +101,23 @@ class MediaGoblinApp(object): ## Routing / controller loading stuff route_match = self.routing.match(path_info) + ## Attach utilities to the request object + request.matchdict = route_match + request.urlgen = routes.URLGenerator(self.routing, environ) + # Do we really want to load this via middleware? Maybe? + request.session = request.environ['beaker.session'] + # Attach self as request.app + # Also attach a few utilities from request.app for convenience? + request.app = self + request.locale = util.get_locale_from_request(request) + + request.template_env = util.get_jinja_env( + self.template_loader, request.locale) + request.db = self.db + request.staticdirect = self.staticdirector + + util.setup_user_in_request(request) + # No matching page? if route_match is None: # Try to do see if we have a match with a trailing slash @@ -121,23 +138,6 @@ class MediaGoblinApp(object): controller = util.import_component(route_match['controller']) request.start_response = start_response - ## Attach utilities to the request object - request.matchdict = route_match - request.urlgen = routes.URLGenerator(self.routing, environ) - # Do we really want to load this via middleware? Maybe? - request.session = request.environ['beaker.session'] - # Attach self as request.app - # Also attach a few utilities from request.app for convenience? - request.app = self - request.locale = util.get_locale_from_request(request) - - request.template_env = util.get_jinja_env( - self.template_loader, request.locale) - request.db = self.db - request.staticdirect = self.staticdirector - - util.setup_user_in_request(request) - return controller(request)(environ, start_response) -- cgit v1.2.3 From bae8f3d8c20b5724abf5ac99776ae582d0a94689 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 20 Aug 2011 15:55:08 -0500 Subject: Adding and making use of the new 404 error page :) --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 96a7ad61..1a115a22 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -133,7 +133,7 @@ class MediaGoblinApp(object): return request.get_response(redirect)(environ, start_response) # Okay, no matches. 404 time! - return exc.HTTPNotFound()(environ, start_response) + return util.render_404(request)(environ, start_response) controller = util.import_component(route_match['controller']) request.start_response = start_response -- cgit v1.2.3 From 3807e8e29c68a44140044ae7711f229dfef5af51 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 20 Aug 2011 15:55:34 -0500 Subject: Tacking on an empty matchdict when 404'ing just in case a template expects it --- mediagoblin/app.py | 1 + 1 file changed, 1 insertion(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 1a115a22..3030929d 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -133,6 +133,7 @@ class MediaGoblinApp(object): return request.get_response(redirect)(environ, start_response) # Okay, no matches. 404 time! + request.matchdict = {} # in case our template expects it return util.render_404(request)(environ, start_response) controller = util.import_component(route_match['controller']) -- cgit v1.2.3 From 0533f117a9ecadbe640281e9721a6e85c9ae1fec Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 23 Aug 2011 23:22:17 -0500 Subject: Basic beaker caching functionality added to the application. --- mediagoblin/app.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 3030929d..113bcb8d 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -25,7 +25,7 @@ from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_workbench, setup_database, - setup_storage) + setup_storage, setup_beaker_cache) class MediaGoblinApp(object): @@ -71,6 +71,9 @@ class MediaGoblinApp(object): # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) + # set up caching + self.cache = setup_beaker_cache() + # Setup celery, if appropriate if setup_celery and not app_config.get('celery_setup_elsewhere'): if os.environ.get('CELERY_ALWAYS_EAGER'): -- cgit v1.2.3 From 12a100e4d8bdda7bd2353403a7e08e3a94669498 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Thu, 1 Sep 2011 20:49:54 -0400 Subject: 508. Updates copyright/license information --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 3030929d..dff61750 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. # # 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 -- cgit v1.2.3 From 0c8a30e61d494b2ec7ee75e5928f6f9d72a31ae4 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sun, 4 Sep 2011 18:15:32 -0700 Subject: Issue 569: Initial framework for application middleware. --- mediagoblin/app.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index dff61750..45b5e3ce 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -20,7 +20,7 @@ import urllib import routes from webob import Request, exc -from mediagoblin import routing, util +from mediagoblin import routing, util, middleware from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init import (get_jinja_loader, get_staticdirector, @@ -61,7 +61,7 @@ class MediaGoblinApp(object): # Get the template environment self.template_loader = get_jinja_loader( app_config.get('user_template_path')) - + # Set up storage systems self.public_store, self.queue_store = setup_storage() @@ -94,11 +94,22 @@ class MediaGoblinApp(object): # matters in always eager mode :) setup_workbench() + # instantiate application middleware + self.middleware = [util.import_component(m)(self) + for m in middleware.ENABLED_MIDDLEWARE] + + def __call__(self, environ, start_response): request = Request(environ) - path_info = request.path_info + + # pass the request through our middleware classes + for m in self.middleware: + response = m.process_request(request) + if response is not None: + return response(environ, start_response) ## Routing / controller loading stuff + path_info = request.path_info route_match = self.routing.match(path_info) ## Attach utilities to the request object @@ -110,7 +121,7 @@ class MediaGoblinApp(object): # Also attach a few utilities from request.app for convenience? request.app = self request.locale = util.get_locale_from_request(request) - + request.template_env = util.get_jinja_env( self.template_loader, request.locale) request.db = self.db @@ -139,7 +150,14 @@ class MediaGoblinApp(object): controller = util.import_component(route_match['controller']) request.start_response = start_response - return controller(request)(environ, start_response) + # get the response from the controller + response = controller(request) + + # pass the response through the middleware + for m in self.middleware[::-1]: + m.process_response(request, response) + + return response(environ, start_response) def paste_app_factory(global_config, **app_config): -- cgit v1.2.3 From ae3bc7fabf8e0abb5f3d8b6534ca451890bbe90b Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Sat, 1 Oct 2011 09:31:42 -0400 Subject: Moved common, translation, template, and url code out of util.py and into tools/[file].py --- mediagoblin/app.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index dd5f0b89..5ee3b973 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,6 +21,7 @@ import routes from webob import Request, exc from mediagoblin import routing, util, middleware +from mediagoblin.tools import translate, template from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init import (get_jinja_loader, get_staticdirector, @@ -123,9 +124,9 @@ class MediaGoblinApp(object): # Attach self as request.app # Also attach a few utilities from request.app for convenience? request.app = self - request.locale = util.get_locale_from_request(request) + request.locale = translate.get_locale_from_request(request) - request.template_env = util.get_jinja_env( + request.template_env = template.get_jinja_env( self.template_loader, request.locale) request.db = self.db request.staticdirect = self.staticdirector -- cgit v1.2.3 From 152a3bfaa36d58e44979f217c5799531f780250f Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Sat, 1 Oct 2011 18:05:44 -0400 Subject: Finished splitting util.py into separate files. --- mediagoblin/app.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 5ee3b973..0f25a4e5 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -20,8 +20,9 @@ import urllib import routes from webob import Request, exc -from mediagoblin import routing, util, middleware -from mediagoblin.tools import translate, template +from mediagoblin import routing, middleware +from mediagoblin.tools import common, translate, template, response +from mediagoblin.tools import request as mg_request from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init import (get_jinja_loader, get_staticdirector, @@ -99,7 +100,7 @@ class MediaGoblinApp(object): setup_workbench() # instantiate application middleware - self.middleware = [util.import_component(m)(self) + self.middleware = [common.import_component(m)(self) for m in middleware.ENABLED_MIDDLEWARE] @@ -131,7 +132,7 @@ class MediaGoblinApp(object): request.db = self.db request.staticdirect = self.staticdirector - util.setup_user_in_request(request) + mg_request.setup_user_in_request(request) # No matching page? if route_match is None: @@ -149,9 +150,9 @@ class MediaGoblinApp(object): # Okay, no matches. 404 time! request.matchdict = {} # in case our template expects it - return util.render_404(request)(environ, start_response) + return response.render_404(request)(environ, start_response) - controller = util.import_component(route_match['controller']) + controller = common.import_component(route_match['controller']) request.start_response = start_response # get the response from the controller -- cgit v1.2.3 From 243c3843bd574129caa7663e25d1a843b2d2dd30 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:02 -0700 Subject: Whitespace and formatting cleanup. * Removed trailing whitespace * Line length < 80 where possible * Honor conventions on number of blank lines * Honor conventions about spaces around :, = --- mediagoblin/app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index dd5f0b89..9bbccf24 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -91,7 +91,7 @@ class MediaGoblinApp(object): # object. ####################################################### - setup_globals(app = self) + setup_globals(app=self) # Workbench *currently* only used by celery, so this only # matters in always eager mode :) @@ -101,7 +101,6 @@ class MediaGoblinApp(object): self.middleware = [util.import_component(m)(self) for m in middleware.ENABLED_MIDDLEWARE] - def __call__(self, environ, start_response): request = Request(environ) -- cgit v1.2.3 From 05788ef450cd63da4009cea1825323e10e572e43 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 3 Oct 2011 14:01:13 +0200 Subject: i592: Use full path in various places When running mediagoblin in a sub path on a web server, most things inside mediagoblin need the "inside path", but when generating URLs for the webbrowser, full paths are needed. urlgen and routes already do that. Some (mostly pagination and login) need the URL of the current page. They used request.path_info. But this is the "inside" path, not the full. So now there is request.full_path and its used in various places. --- mediagoblin/app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 0f25a4e5..f052d4a2 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -117,6 +117,17 @@ class MediaGoblinApp(object): path_info = request.path_info route_match = self.routing.match(path_info) + # By using fcgi, mediagoblin can run under a base path + # like /mediagoblin/. request.path_info contains the + # path inside mediagoblin. If the something needs the + # full path of the current page, that should include + # the basepath. + # Note: urlgen and routes are fine! + request.full_path = environ["SCRIPT_NAME"] + request.path_info + # python-routes uses SCRIPT_NAME. So let's use that too. + # The other option would be: + # request.full_path = environ["SCRIPT_URL"] + ## Attach utilities to the request object request.matchdict = route_match request.urlgen = routes.URLGenerator(self.routing, environ) -- cgit v1.2.3 From c0022ecc8803d92f2ecedbcce90037a8b48dac77 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 5 Oct 2011 20:57:02 -0500 Subject: Fixing 404s, related to recent util refactoring. --- mediagoblin/app.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 0f25a4e5..a72b9306 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,7 +21,8 @@ import routes from webob import Request, exc from mediagoblin import routing, middleware -from mediagoblin.tools import common, translate, template, response +from mediagoblin.tools import common, translate, template +from mediagoblin.tools.response import render_404 from mediagoblin.tools import request as mg_request from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config @@ -150,7 +151,7 @@ class MediaGoblinApp(object): # Okay, no matches. 404 time! request.matchdict = {} # in case our template expects it - return response.render_404(request)(environ, start_response) + return render_404(request)(environ, start_response) controller = common.import_component(route_match['controller']) request.start_response = start_response -- cgit v1.2.3 From 91903aa601813f4ce7ea8259aa8fe2910b576311 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 29 Oct 2011 17:04:19 -0500 Subject: [620] Allow for multiple mediagoblin configs to be set in config.ini, use first This way we can copy paste.ini into paste_local.ini but not have to update it to find mediagoblin_local.ini. --- mediagoblin/app.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ee646282..d39469c3 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -178,6 +178,16 @@ class MediaGoblinApp(object): def paste_app_factory(global_config, **app_config): - mgoblin_app = MediaGoblinApp(app_config['config']) + configs = app_config['config'].split() + mediagoblin_config = None + for config in configs: + if os.path.exists(config) and os.access(config, os.R_OK): + mediagoblin_config = config + break + + if not mediagoblin_config: + raise IOError("Usable mediagoblin config not found.") + + mgoblin_app = MediaGoblinApp(mediagoblin_config) return mgoblin_app -- cgit v1.2.3 From ce5ae8da19707019cd62d42533e591d71071f4fe Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 25 Nov 2011 12:13:56 -0600 Subject: Rename MediaGoblin middleware to meddleware to avoid confusion w/ wsgi middleware hehehehehe, "meddleware" --- mediagoblin/app.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ce4b0bec..aafadd97 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -20,7 +20,7 @@ import urllib import routes from webob import Request, exc -from mediagoblin import routing, middleware +from mediagoblin import routing, meddleware from mediagoblin.tools import common, translate, template from mediagoblin.tools.response import render_404 from mediagoblin.tools import request as mg_request @@ -100,15 +100,15 @@ class MediaGoblinApp(object): # matters in always eager mode :) setup_workbench() - # instantiate application middleware - self.middleware = [common.import_component(m)(self) - for m in middleware.ENABLED_MIDDLEWARE] + # instantiate application meddleware + self.meddleware = [common.import_component(m)(self) + for m in meddleware.ENABLED_MEDDLEWARE] def __call__(self, environ, start_response): request = Request(environ) - # pass the request through our middleware classes - for m in self.middleware: + # pass the request through our meddleware classes + for m in self.meddleware: response = m.process_request(request) if response is not None: return response(environ, start_response) @@ -169,8 +169,8 @@ class MediaGoblinApp(object): # get the response from the controller response = controller(request) - # pass the response through the middleware - for m in self.middleware[::-1]: + # pass the response through the meddleware + for m in self.meddleware[::-1]: m.process_response(request, response) return response(environ, start_response) -- cgit v1.2.3 From 91cf67385a78a59af7874df327b96f7ea0b4259b Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 26 Nov 2011 14:34:36 -0800 Subject: Issue 680: Dispatch meddleware request processing post-routing --- mediagoblin/app.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index aafadd97..7f087ed9 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -107,12 +107,6 @@ class MediaGoblinApp(object): def __call__(self, environ, start_response): request = Request(environ) - # pass the request through our meddleware classes - for m in self.meddleware: - response = m.process_request(request) - if response is not None: - return response(environ, start_response) - ## Routing / controller loading stuff path_info = request.path_info route_match = self.routing.match(path_info) @@ -164,6 +158,13 @@ class MediaGoblinApp(object): return render_404(request)(environ, start_response) controller = common.import_component(route_match['controller']) + + # pass the request through our meddleware classes + for m in self.meddleware: + response = m.process_request(request, controller) + if response is not None: + return response(environ, start_response) + request.start_response = start_response # get the response from the controller -- cgit v1.2.3 From 1e9d1acc03aa42ff979c8d15162d51441b81ec5d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 2 Dec 2011 16:13:14 -0600 Subject: We should use the variable local_templates instead of user_template_path --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 7f087ed9..04eb2acc 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -63,7 +63,7 @@ class MediaGoblinApp(object): # Get the template environment self.template_loader = get_jinja_loader( - app_config.get('user_template_path')) + app_config.get('local_templates')) # Set up storage systems self.public_store, self.queue_store = setup_storage() -- cgit v1.2.3 From 871fc591dd2492d2bdca0a530fdffac14f3feece Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 21 Dec 2011 00:06:38 +0100 Subject: Workaround for Routes/urlgen bug. This is relevant for fcgi: Some servers (cherokee for example) put "HTTP":"off" in the environ. And the following code in urlgen breaks on this: if environ.get('HTTPS') or environ.get('wsgi.url_scheme') == 'https' \ or environ.get('HTTP_X_FORWARDED_PROTO') == 'https': hostinfo['protocol'] = 'https' workaround is to remove HTTPS:off from the environ. --- mediagoblin/app.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 04eb2acc..49dc8d97 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -122,6 +122,10 @@ class MediaGoblinApp(object): # The other option would be: # request.full_path = environ["SCRIPT_URL"] + # Fix up environ for urlgen + if environ.get('HTTPS', '').lower() == 'off': + environ.pop('HTTPS') + ## Attach utilities to the request object request.matchdict = route_match request.urlgen = routes.URLGenerator(self.routing, environ) -- cgit v1.2.3 From d23d4b23dad2e14e330664f58994dcbbbaa32720 Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 21 Dec 2011 00:34:02 +0100 Subject: Note reported bug in workaround So that the workaround can eventually be removed, note the URL for the relevant bug in a comment. --- mediagoblin/app.py | 1 + 1 file changed, 1 insertion(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 49dc8d97..96b2c8ab 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -123,6 +123,7 @@ class MediaGoblinApp(object): # request.full_path = environ["SCRIPT_URL"] # Fix up environ for urlgen + # See bug: https://bitbucket.org/bbangert/routes/issue/55/cache_hostinfo-breaks-on-https-off if environ.get('HTTPS', '').lower() == 'off': environ.pop('HTTPS') -- cgit v1.2.3 From cf29e8a824e0ef4612f1144f079c80c1d20b89e5 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 2 Feb 2012 09:44:13 -0600 Subject: It's 2012 all up in here --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 96b2c8ab..06627675 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # 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 -- cgit v1.2.3 From ec97c937b7e3374d40624478f805694b56bc0317 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 26 Feb 2012 18:45:35 +0100 Subject: Let Main Server emit startup notice including version There was no place in the software telling the user the version in use. So start by having the main server emit a startup notice including the version string. Uses python logging, so should be easy to reconfigure, etc. --- mediagoblin/app.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 06627675..15327d39 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -16,11 +16,12 @@ import os import urllib +import logging import routes from webob import Request, exc -from mediagoblin import routing, meddleware +from mediagoblin import routing, meddleware, __version__ from mediagoblin.tools import common, translate, template from mediagoblin.tools.response import render_404 from mediagoblin.tools import request as mg_request @@ -31,6 +32,9 @@ from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_storage, setup_beaker_cache) +_log = logging.getLogger(__name__) + + class MediaGoblinApp(object): """ WSGI application of MediaGoblin @@ -47,6 +51,7 @@ class MediaGoblinApp(object): (Note: setting 'celery_setup_elsewhere' also disables setting up celery.) """ + _log.info("GNU MediaGoblin %s main server starting", __version__) ############## # Setup config ############## -- cgit v1.2.3 From 2bc8ff0d63188f2168553d39ebf8756ae83053e1 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 28 Jan 2012 13:10:01 +0100 Subject: Cleanup Session after each request. It's good practice to cleanup the SQL session after each request so that the next request gets a fresh one. It's an application decision whether one wants a just-in-case ROLLBACK or COMMIT. There are two ideas behind it, really. I have decided for ROLLBACK. The idea is "if you forget to commit your changes yourself, there's something broken. Maybe you got an exception?". --- mediagoblin/app.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 15327d39..0a57c091 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -184,6 +184,14 @@ class MediaGoblinApp(object): for m in self.meddleware[::-1]: m.process_response(request, response) + # Reset the sql session, so that the next request + # gets a fresh session + try: + self.db.reset_after_request() + except TypeError: + # We're still on mongo + pass + return response(environ, start_response) -- cgit v1.2.3 From e824570a23b3939803cee8a3fd6df0fd5e754de0 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 7 Apr 2012 23:21:59 +0200 Subject: Cleanup sql session after request. ALWAYS! The cleanup could be missed if the request handling code in app.py:__call__ exits early (due to exception, or due to one of those early "return"s). So to make sure the sql session is cleaned up for real, wrap the whole thing in a try: finally:. Also wrote a short tool to test if the session is actually empty. The tool is currently disabled, but ready to be used. --- mediagoblin/app.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 0a57c091..b7ca092d 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -109,7 +109,7 @@ class MediaGoblinApp(object): self.meddleware = [common.import_component(m)(self) for m in meddleware.ENABLED_MEDDLEWARE] - def __call__(self, environ, start_response): + def call_backend(self, environ, start_response): request = Request(environ) ## Routing / controller loading stuff @@ -184,15 +184,18 @@ class MediaGoblinApp(object): for m in self.meddleware[::-1]: m.process_response(request, response) - # Reset the sql session, so that the next request - # gets a fresh session + return response(environ, start_response) + + def __call__(self, environ, start_response): + ## If more errors happen that look like unclean sessions: + # self.db.check_session_clean() + try: + return self.call_backend(environ, start_response) + finally: + # Reset the sql session, so that the next request + # gets a fresh session self.db.reset_after_request() - except TypeError: - # We're still on mongo - pass - - return response(environ, start_response) def paste_app_factory(global_config, **app_config): -- cgit v1.2.3 From 8a0d35e72aa50ca9add0f1e47e40ef7c8c5de039 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 8 Apr 2012 09:54:32 -0500 Subject: Allow users to pass callables in as controllers, not just import paths --- mediagoblin/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index b7ca092d..99c7de76 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -167,7 +167,13 @@ class MediaGoblinApp(object): request.matchdict = {} # in case our template expects it return render_404(request)(environ, start_response) - controller = common.import_component(route_match['controller']) + # import the controller, or if it's already a callable, call that + route_controller = route_match['controller'] + if isinstance(route_controller, unicode) \ + or isinstance(route_controller, str): + controller = common.import_component(route_match['controller']) + else: + controller = route_match['controller'] # pass the request through our meddleware classes for m in self.meddleware: -- cgit v1.2.3 From d9a31a39801fe0a4476b33ab60f254eb04b50a3f Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 8 Apr 2012 10:43:23 -0500 Subject: CELERY_ALWAYS_EAGER environment variable only recognized if 'true' now --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 99c7de76..ef166047 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -84,7 +84,7 @@ class MediaGoblinApp(object): # Setup celery, if appropriate if setup_celery and not app_config.get('celery_setup_elsewhere'): - if os.environ.get('CELERY_ALWAYS_EAGER'): + if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true': setup_celery_from_config( app_config, global_config, force_celery_always_eager=True) -- cgit v1.2.3 From 3f36967401c5f7459817c7229a4f76c7b891ec8a Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 9 Apr 2012 22:49:41 +0200 Subject: log.debug the used config file. Might be useful at some point. --- mediagoblin/app.py | 1 + 1 file changed, 1 insertion(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ef166047..511c363c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -52,6 +52,7 @@ class MediaGoblinApp(object): setting up celery.) """ _log.info("GNU MediaGoblin %s main server starting", __version__) + _log.debug("Using config file %s", config_path) ############## # Setup config ############## -- cgit v1.2.3 From 29b6f91740e68d804612ff68295020f6cfa16071 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Mon, 12 Mar 2012 21:17:08 -0400 Subject: 401. Plugin infrastructure * implements installing, loading and setup for plugins * codifies configuration * has a sample plugin * docs * tests --- mediagoblin/app.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 511c363c..97080ed8 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -27,6 +27,7 @@ from mediagoblin.tools.response import render_404 from mediagoblin.tools import request as mg_request from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config +from mediagoblin.init.plugins import setup_plugins from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_workbench, setup_database, setup_storage, setup_beaker_cache) @@ -64,6 +65,11 @@ class MediaGoblinApp(object): # Setup other connections / useful objects ########################################## + # Set up plugins -- need to do this early so that plugins can + # affect startup. + _log.info("Setting up plugins.") + setup_plugins() + # Set up the database self.connection, self.db = setup_database() -- cgit v1.2.3 From 828fc6300a5e9d1cf8cd10e875945ce7a8c3a1ab Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 30 Jun 2012 17:34:04 -0500 Subject: Early version of theme registry code --- mediagoblin/app.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 97080ed8..33acbba0 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -24,6 +24,7 @@ from webob import Request, exc from mediagoblin import routing, meddleware, __version__ from mediagoblin.tools import common, translate, template from mediagoblin.tools.response import render_404 +from mediagoblin.tools.theme import register_themes from mediagoblin.tools import request as mg_request from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config @@ -73,6 +74,9 @@ class MediaGoblinApp(object): # Set up the database self.connection, self.db = setup_database() + # Register themes + self.theme_registry = register_themes(app_config) + # Get the template environment self.template_loader = get_jinja_loader( app_config.get('local_templates')) -- cgit v1.2.3 From 3b47da8eab4ac8b4b580fb95da2d4a3e891e9555 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 5 Jul 2012 12:23:56 -0500 Subject: Themes are now registered and can have their templates loaded properly --- mediagoblin/app.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 33acbba0..a10edfaa 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -76,10 +76,17 @@ class MediaGoblinApp(object): # Register themes self.theme_registry = register_themes(app_config) + self.current_theme_name = app_config.get('theme') + if self.current_theme_name \ + and self.theme_registry.has_key(self.current_theme_name): + self.current_theme = self.theme_registry[self.current_theme_name] + else: + self.current_theme = None # Get the template environment self.template_loader = get_jinja_loader( - app_config.get('local_templates')) + app_config.get('local_templates'), + self.current_theme) # Set up storage systems self.public_store, self.queue_store = setup_storage() -- cgit v1.2.3 From 975be468cfc47e14cafb1b1bc8a6eb0e9f3704a0 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 13 Jul 2012 12:33:52 -0500 Subject: Making the register_themes() tool also return the current theme This will reduce the amount of work reproducing this behavior when pulling together the theme registry elsewhere. --- mediagoblin/app.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index a10edfaa..dfc715b9 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -75,13 +75,7 @@ class MediaGoblinApp(object): self.connection, self.db = setup_database() # Register themes - self.theme_registry = register_themes(app_config) - self.current_theme_name = app_config.get('theme') - if self.current_theme_name \ - and self.theme_registry.has_key(self.current_theme_name): - self.current_theme = self.theme_registry[self.current_theme_name] - else: - self.current_theme = None + self.theme_registry, self.current_theme = register_themes(app_config) # Get the template environment self.template_loader = get_jinja_loader( -- cgit v1.2.3 From 8545dd50f0cd588d505c217d367450198199a2b0 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Sun, 10 Jun 2012 11:50:14 -0400 Subject: Flatpages first pass This fixes the template loader so that it can load plugin templates. This adds code for registering template paths so that plugins can add their own templates. This adds the base code for the flatpagesfile plugin. It doesn't serve pages, yet, but it's pretty close. --- mediagoblin/app.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index dfc715b9..4870b89c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -32,6 +32,7 @@ from mediagoblin.init.plugins import setup_plugins from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_workbench, setup_database, setup_storage, setup_beaker_cache) +from mediagoblin.tools.pluginapi import PluginCache _log = logging.getLogger(__name__) @@ -80,7 +81,9 @@ class MediaGoblinApp(object): # Get the template environment self.template_loader = get_jinja_loader( app_config.get('local_templates'), - self.current_theme) + self.current_theme, + PluginCache().get_template_paths() + ) # Set up storage systems self.public_store, self.queue_store = setup_storage() -- cgit v1.2.3 From 4bd65f69c710268404e1b1fdaac68db069558584 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Sun, 10 Jun 2012 14:51:13 -0400 Subject: Finish flatpagesplugin; add plugin docs --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 4870b89c..9ef23ce8 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -89,7 +89,7 @@ class MediaGoblinApp(object): self.public_store, self.queue_store = setup_storage() # set up routing - self.routing = routing.get_mapper() + self.routing = routing.get_mapper(PluginCache().get_routes()) # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) -- cgit v1.2.3 From 05e007c1dbe7b5b8a092f1a99ed361c4e6b71f26 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Tue, 17 Jul 2012 21:02:12 -0400 Subject: Rework plugin infrastructure to nix side-effects This reworks the plugin infrastructure so as to remove module-loading side-effects which were making things a pain in the ass to test. With the new system, there's no auto-registering meta class. Instead plugins do whatever they want and then specify a hooks dict that maps hook names to callables for the things they're tying into. The most common one (and the only one we've implemented so far) is "setup". This also simplifies the sampleplugin a little by moving the code to __init__.py. --- mediagoblin/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 9ef23ce8..51f5899a 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -32,7 +32,7 @@ from mediagoblin.init.plugins import setup_plugins from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_workbench, setup_database, setup_storage, setup_beaker_cache) -from mediagoblin.tools.pluginapi import PluginCache +from mediagoblin.tools.pluginapi import PluginManager _log = logging.getLogger(__name__) @@ -82,14 +82,14 @@ class MediaGoblinApp(object): self.template_loader = get_jinja_loader( app_config.get('local_templates'), self.current_theme, - PluginCache().get_template_paths() + PluginManager().get_template_paths() ) # Set up storage systems self.public_store, self.queue_store = setup_storage() # set up routing - self.routing = routing.get_mapper(PluginCache().get_routes()) + self.routing = routing.get_mapper(PluginManager().get_routes()) # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) -- cgit v1.2.3 From f1d06e1d6c604c72028082a477248d26e81cad5b Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Thu, 27 Sep 2012 21:41:48 +0200 Subject: Switch from webob.Request to werkzeug.wrappers.Request --- mediagoblin/app.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 51f5899a..30ac3e01 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -19,7 +19,8 @@ import urllib import logging import routes -from webob import Request, exc +from webob import exc +from werkzeug.wrappers import Request from mediagoblin import routing, meddleware, __version__ from mediagoblin.tools import common, translate, template @@ -127,8 +128,14 @@ class MediaGoblinApp(object): def call_backend(self, environ, start_response): request = Request(environ) + ## Compatibility webob -> werkzeug + request.GET = request.args + request.POST = request.form + request.accept_language = request.accept_languages + request.accept = request.accept_mimetypes + ## Routing / controller loading stuff - path_info = request.path_info + path_info = request.path route_match = self.routing.match(path_info) # By using fcgi, mediagoblin can run under a base path @@ -137,7 +144,7 @@ class MediaGoblinApp(object): # full path of the current page, that should include # the basepath. # Note: urlgen and routes are fine! - request.full_path = environ["SCRIPT_NAME"] + request.path_info + request.full_path = environ["SCRIPT_NAME"] + request.path # python-routes uses SCRIPT_NAME. So let's use that too. # The other option would be: # request.full_path = environ["SCRIPT_URL"] -- cgit v1.2.3 From 111a609df526bd3690fc03e623eaf5826f33f4d2 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sat, 29 Sep 2012 21:07:15 +0200 Subject: Replaced all request.POST with request.form, ... - Fixed error handling in OAuth plugin - Changed request.POST file fields to request.files --- mediagoblin/app.py | 1 - 1 file changed, 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 30ac3e01..08515df9 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -130,7 +130,6 @@ class MediaGoblinApp(object): ## Compatibility webob -> werkzeug request.GET = request.args - request.POST = request.form request.accept_language = request.accept_languages request.accept = request.accept_mimetypes -- cgit v1.2.3 From 7742dcc1fbda04c3a1c76a057a1a93a8f504502e Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 14 Oct 2012 13:46:31 +0200 Subject: Switched most stuff over from Routes Removed the Routes routing functionality and replaced it with werkzeug.routes. Most views are functional. Known issues: - Translation integration with the request object is not yet figured out. This breaks 404 pages. --- mediagoblin/app.py | 73 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 32 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 08515df9..5758dbbb 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -18,11 +18,12 @@ import os import urllib import logging -import routes -from webob import exc +from mediagoblin.routing import url_map, view_functions, add_route + from werkzeug.wrappers import Request +from werkzeug.exceptions import HTTPException, NotFound -from mediagoblin import routing, meddleware, __version__ +from mediagoblin import meddleware, __version__ from mediagoblin.tools import common, translate, template from mediagoblin.tools.response import render_404 from mediagoblin.tools.theme import register_themes @@ -90,7 +91,10 @@ class MediaGoblinApp(object): self.public_store, self.queue_store = setup_storage() # set up routing - self.routing = routing.get_mapper(PluginManager().get_routes()) + self.url_map = url_map + + for route in PluginManager().get_routes(): + add_route(*route) # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) @@ -135,7 +139,7 @@ class MediaGoblinApp(object): ## Routing / controller loading stuff path_info = request.path - route_match = self.routing.match(path_info) + map_adapter = self.url_map.bind_to_environ(request.environ) # By using fcgi, mediagoblin can run under a base path # like /mediagoblin/. request.path_info contains the @@ -154,47 +158,52 @@ class MediaGoblinApp(object): environ.pop('HTTPS') ## Attach utilities to the request object - request.matchdict = route_match - request.urlgen = routes.URLGenerator(self.routing, environ) # Do we really want to load this via middleware? Maybe? request.session = request.environ['beaker.session'] # Attach self as request.app # Also attach a few utilities from request.app for convenience? request.app = self - request.locale = translate.get_locale_from_request(request) - request.template_env = template.get_jinja_env( - self.template_loader, request.locale) request.db = self.db request.staticdirect = self.staticdirector mg_request.setup_user_in_request(request) - # No matching page? - if route_match is None: - # Try to do see if we have a match with a trailing slash - # added and if so, redirect - if not path_info.endswith('/') \ - and request.method == 'GET' \ - and self.routing.match(path_info + '/'): - new_path_info = path_info + '/' - if request.GET: - new_path_info = '%s?%s' % ( - new_path_info, urllib.urlencode(request.GET)) - redirect = exc.HTTPFound(location=new_path_info) - return request.get_response(redirect)(environ, start_response) - - # Okay, no matches. 404 time! - request.matchdict = {} # in case our template expects it + try: + endpoint, url_values = map_adapter.match() + request.matchdict = url_values + + request.locale = translate.get_locale_from_request(request) + request.template_env = template.get_jinja_env( + self.template_loader, request.locale) + except NotFound as exc: + return NotImplemented return render_404(request)(environ, start_response) + except HTTPException as exc: + # Support legacy webob.exc responses + return exc(environ, start_response) + + def build_proxy(endpoint, **kw): + try: + qualified = kw.pop('qualified') + except KeyError: + qualified = False + + return map_adapter.build( + endpoint, + values=dict(**kw), + force_external=qualified) + + request.urlgen = build_proxy + + view_func = view_functions[endpoint] - # import the controller, or if it's already a callable, call that - route_controller = route_match['controller'] - if isinstance(route_controller, unicode) \ - or isinstance(route_controller, str): - controller = common.import_component(route_match['controller']) + # import the endpoint, or if it's already a callable, call that + if isinstance(view_func, unicode) \ + or isinstance(view_func, str): + controller = common.import_component(view_func) else: - controller = route_match['controller'] + controller = view_func # pass the request through our meddleware classes for m in self.meddleware: -- cgit v1.2.3 From 1ec7ff2adbb1821c5318b4e0a18194f441d7a87e Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 14 Oct 2012 20:05:44 +0200 Subject: Fixed 404 page under werkzeug.routing - Removed ?lang= feature due to incompatibility with werkzeug routes in the current state of the architecture. --- mediagoblin/app.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 5758dbbb..8a19b3e0 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -15,7 +15,6 @@ # along with this program. If not, see . import os -import urllib import logging from mediagoblin.routing import url_map, view_functions, add_route @@ -138,7 +137,6 @@ class MediaGoblinApp(object): request.accept = request.accept_mimetypes ## Routing / controller loading stuff - path_info = request.path map_adapter = self.url_map.bind_to_environ(request.environ) # By using fcgi, mediagoblin can run under a base path @@ -167,21 +165,9 @@ class MediaGoblinApp(object): request.db = self.db request.staticdirect = self.staticdirector - mg_request.setup_user_in_request(request) - - try: - endpoint, url_values = map_adapter.match() - request.matchdict = url_values - - request.locale = translate.get_locale_from_request(request) - request.template_env = template.get_jinja_env( - self.template_loader, request.locale) - except NotFound as exc: - return NotImplemented - return render_404(request)(environ, start_response) - except HTTPException as exc: - # Support legacy webob.exc responses - return exc(environ, start_response) + request.locale = translate.get_locale_from_request(request) + request.template_env = template.get_jinja_env( + self.template_loader, request.locale) def build_proxy(endpoint, **kw): try: @@ -196,8 +182,23 @@ class MediaGoblinApp(object): request.urlgen = build_proxy + mg_request.setup_user_in_request(request) + + try: + endpoint, url_values = map_adapter.match() + request.matchdict = url_values + except NotFound as exc: + return render_404(request)(environ, start_response) + except HTTPException as exc: + # Support legacy webob.exc responses + return exc(environ, start_response) + view_func = view_functions[endpoint] + _log.debug('endpoint: {0} view_func: {1}'.format( + endpoint, + view_func)) + # import the endpoint, or if it's already a callable, call that if isinstance(view_func, unicode) \ or isinstance(view_func, str): -- cgit v1.2.3 From d56e82635f85f7a8a7d184a3eae539c09a7b001d Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Mon, 15 Oct 2012 00:12:58 +0200 Subject: Fixed OAuth access_token duplicate route Changed route name to "[...]list_connections" --- mediagoblin/app.py | 1 + 1 file changed, 1 insertion(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 8a19b3e0..3a2d00f0 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -93,6 +93,7 @@ class MediaGoblinApp(object): self.url_map = url_map for route in PluginManager().get_routes(): + _log.debug('adding plugin route: {0}'.format(route)) add_route(*route) # set up staticdirector tool -- cgit v1.2.3 From 7b9f9d1edb96aabab7e35818824b71efbdd4efb9 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Sat, 1 Dec 2012 23:35:52 +0100 Subject: Fix i18n in our browser We only ever served english pages since the switch to werkzeug's requests. Fix this by actually checking the accepted languages that our web browser sends and using that or falling back to english. This is not optimal, imaging our browser sends "klingon, de" as accepted languages and we happen to not have a klingon translation ready (a deficiency that should be corrected immediately anyway!!). We would then fall back to english rather than sending the sensible and pleasant German language which the user would understand. This will require more backend work though. Removing the gettext.find() in mg_globals.py. It looked in the wrong directory anyway (mediagoblin/translations) and as that does not exist, had always returned None without anyone noticing. Signed-off-by: Sebastian Spaeth --- mediagoblin/app.py | 1 - 1 file changed, 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 3a2d00f0..de421aca 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -134,7 +134,6 @@ class MediaGoblinApp(object): ## Compatibility webob -> werkzeug request.GET = request.args - request.accept_language = request.accept_languages request.accept = request.accept_mimetypes ## Routing / controller loading stuff -- cgit v1.2.3 From 6ef75af50ecd9b71a5d9455f616c421b1d84b732 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Sun, 2 Dec 2012 00:29:30 +0100 Subject: Honor user's browser language (#558) Previously we would attempt to satisfy the user's first language preference, immediately falling back to english if that was not possible. Now, we will get the best match of the user's preferred languages. This requires storing the available locales on app startup, so we have mg_globals.available_locales ready to compare them against the list of preferred user languages. Signed-off-by: Sebastian Spaeth --- mediagoblin/app.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index de421aca..876ded4e 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -31,7 +31,7 @@ from mediagoblin.mg_globals import setup_globals from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init.plugins import setup_plugins from mediagoblin.init import (get_jinja_loader, get_staticdirector, - setup_global_and_app_config, setup_workbench, setup_database, + setup_global_and_app_config, setup_locales, setup_workbench, setup_database, setup_storage, setup_beaker_cache) from mediagoblin.tools.pluginapi import PluginManager @@ -68,6 +68,9 @@ class MediaGoblinApp(object): # Setup other connections / useful objects ########################################## + # load all available locales + setup_locales() + # Set up plugins -- need to do this early so that plugins can # affect startup. _log.info("Setting up plugins.") -- cgit v1.2.3 From b745bb50d8a4c92b5adbbd6918262ff8c9cc9609 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 16 Nov 2012 10:25:50 +0100 Subject: Remove webob from render_to_response We were still using webob's Response objects for template rendering. Transition to werkzeug's Response object. One caveat was that it seemed to have used the default mimetype "text/plain" for all pages, so we override the default Response class, setting the default mime type to "text/html". Signed-off-by: Sebastian Spaeth --- mediagoblin/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 876ded4e..8bd2496f 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -193,7 +193,8 @@ class MediaGoblinApp(object): except NotFound as exc: return render_404(request)(environ, start_response) except HTTPException as exc: - # Support legacy webob.exc responses + # exceptions that match() is documented to return: + # MethodNotAllowed, RequestRedirect TODO: need to handle ??? return exc(environ, start_response) view_func = view_functions[endpoint] -- cgit v1.2.3 From 726896b62a87a88594cf3863f4bbfcaf84b2abb3 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 16 Nov 2012 11:36:04 +0100 Subject: Remove webob compatability Remove the aliases we provided for webob compatability as webob is now gone. Grepped the code base to check for occurences of the old parameters to be safe. Keep request.GET attribute as alias for request.args as it is often used and django is also using that attribute. Signed-off-by: Sebastian Spaeth --- mediagoblin/app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 8bd2496f..9e06e52d 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -135,9 +135,8 @@ class MediaGoblinApp(object): def call_backend(self, environ, start_response): request = Request(environ) - ## Compatibility webob -> werkzeug + # Compatibility with django, use request.args preferrably request.GET = request.args - request.accept = request.accept_mimetypes ## Routing / controller loading stuff map_adapter = self.url_map.bind_to_environ(request.environ) -- cgit v1.2.3 From 573b4305cd077577b325d7b3ba9a65d3308e4061 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 21 Dec 2012 08:20:54 +0100 Subject: Don't dbug log every added plugin route It is killing testsuite output by drowning out all signals. It should be sufficient to state in the pluginmanager that routes have been added, if we need that kind of output. Signed-off-by: Sebastian Spaeth --- mediagoblin/app.py | 1 - 1 file changed, 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 9e06e52d..1a398bcd 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -96,7 +96,6 @@ class MediaGoblinApp(object): self.url_map = url_map for route in PluginManager().get_routes(): - _log.debug('adding plugin route: {0}'.format(route)) add_route(*route) # set up staticdirector tool -- cgit v1.2.3 From 785b287fcb42ac9130b222006097e3f68cec3543 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Sun, 23 Dec 2012 11:57:45 +0100 Subject: Provide tools.response.render_http_exception and use that After the webob->werkzeug transition, controller functions can raise werkzeug.HttpExceptions. We need to catch these in app.py when calling the controller and handle them, rendering the corresponding error Response() object. For consistency, we also want to allow meddleware functions to raise HttpExceptions (e.g. the csrf meddleware needs to complain about lack of cookies), so wrap the request and response parts of the meddleware too. Finally, the urlmap.match() can also raise HttpExceptions, so we give it the same treatment (render_http_exception). I am not sure, if we do not need to handle the Redirect exception there in any different way though... The new function render_http_exception makes use of the render_error infrastructure to return a nicely templated error page. It also checks if the stock error messages was used in cases where we have localizations (403, 404) and use those. It is now possible to do things like "raise Forbidden(_('You suckr'))" or raise NotFound(_('where is my left show again')) if you want to return customized error messages to the user. Signed-off-by: Sebastian Spaeth --- mediagoblin/app.py | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 1a398bcd..d1f4cab7 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -24,7 +24,7 @@ from werkzeug.exceptions import HTTPException, NotFound from mediagoblin import meddleware, __version__ from mediagoblin.tools import common, translate, template -from mediagoblin.tools.response import render_404 +from mediagoblin.tools.response import render_http_exception from mediagoblin.tools.theme import register_themes from mediagoblin.tools import request as mg_request from mediagoblin.mg_globals import setup_globals @@ -188,12 +188,11 @@ class MediaGoblinApp(object): try: endpoint, url_values = map_adapter.match() request.matchdict = url_values - except NotFound as exc: - return render_404(request)(environ, start_response) except HTTPException as exc: - # exceptions that match() is documented to return: - # MethodNotAllowed, RequestRedirect TODO: need to handle ??? - return exc(environ, start_response) + # Stop and render exception + return render_http_exception( + request, exc, + exc.get_description(environ))(environ, start_response) view_func = view_functions[endpoint] @@ -209,19 +208,32 @@ class MediaGoblinApp(object): controller = view_func # pass the request through our meddleware classes - for m in self.meddleware: - response = m.process_request(request, controller) - if response is not None: - return response(environ, start_response) + try: + for m in self.meddleware: + response = m.process_request(request, controller) + if response is not None: + return response(environ, start_response) + except HTTPException as e: + return render_http_exception( + request, e, + e.get_description(environ))(environ, start_response) request.start_response = start_response - # get the response from the controller - response = controller(request) + # get the Http response from the controller + try: + response = controller(request) + except HTTPException as e: + response = render_http_exception( + request, e, e.get_description(environ)) - # pass the response through the meddleware - for m in self.meddleware[::-1]: - m.process_response(request, response) + # pass the response through the meddlewares + try: + for m in self.meddleware[::-1]: + m.process_response(request, response) + except HTTPException as e: + response = render_http_exeption( + request, e, e.get_description(environ)) return response(environ, start_response) -- cgit v1.2.3 From 48cf435d718b47e33cb98b048e5b58d79a46b486 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 1 Dec 2012 21:36:18 +0100 Subject: Refactor routing in app.py. Move some things out of app.py into functions in routing.py. This makes app.py a bit more readable and allows us to rewrite routing. --- mediagoblin/app.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index d1f4cab7..207e9d2c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -17,7 +17,7 @@ import os import logging -from mediagoblin.routing import url_map, view_functions, add_route +from mediagoblin.routing import get_url_map, endpoint_to_controller from werkzeug.wrappers import Request from werkzeug.exceptions import HTTPException, NotFound @@ -93,10 +93,7 @@ class MediaGoblinApp(object): self.public_store, self.queue_store = setup_storage() # set up routing - self.url_map = url_map - - for route in PluginManager().get_routes(): - add_route(*route) + self.url_map = get_url_map() # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) @@ -194,18 +191,7 @@ class MediaGoblinApp(object): request, exc, exc.get_description(environ))(environ, start_response) - view_func = view_functions[endpoint] - - _log.debug('endpoint: {0} view_func: {1}'.format( - endpoint, - view_func)) - - # import the endpoint, or if it's already a callable, call that - if isinstance(view_func, unicode) \ - or isinstance(view_func, str): - controller = common.import_component(view_func) - else: - controller = view_func + controller = endpoint_to_controller(endpoint) # pass the request through our meddleware classes try: -- cgit v1.2.3 From 3d9143323019e0793451eac60eef8e55c09f6c47 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 16 Dec 2012 00:50:20 +0100 Subject: Move things from routing.py to tools/routing.py This stops a cyclic import. Move add_route, mount and endpoint_to_controller into tools/routing.py and change all callers. --- mediagoblin/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 207e9d2c..ff64f65c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -17,7 +17,8 @@ import os import logging -from mediagoblin.routing import get_url_map, endpoint_to_controller +from mediagoblin.routing import get_url_map +from mediagoblin.tools.routing import endpoint_to_controller from werkzeug.wrappers import Request from werkzeug.exceptions import HTTPException, NotFound -- cgit v1.2.3 From 05501c5742c85d0e2c855a02800d1f50f9df6c3d Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 16 Dec 2012 00:45:57 +0100 Subject: Rewrite routing using new MGRoute class MGRoute subclasses Rule(): Rule doesn't have a way to tag extra data, like the controller function, we need. So MGRoute has a new attribute .gmg_controller, which holds this. Rewrite everything to use this new Rule variant and drop all the other stuff that mapped endpoints to controller functions, mostly. --- mediagoblin/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ff64f65c..936a354f 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -184,7 +184,7 @@ class MediaGoblinApp(object): mg_request.setup_user_in_request(request) try: - endpoint, url_values = map_adapter.match() + found_rule, url_values = map_adapter.match(return_rule=True) request.matchdict = url_values except HTTPException as exc: # Stop and render exception @@ -192,7 +192,7 @@ class MediaGoblinApp(object): request, exc, exc.get_description(environ))(environ, start_response) - controller = endpoint_to_controller(endpoint) + controller = endpoint_to_controller(found_rule) # pass the request through our meddleware classes try: -- cgit v1.2.3 From bc142abc5592975c08319416d0af12c108504887 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 29 Nov 2012 17:23:28 +0100 Subject: RIP out mongo Since sqlalchemy is providing our database abstraction and we have moved away from Mongo as the underlying database, it is now time to simplify things and rip out mongo. This provides the bulk of the changes, and can stand on its own. There are some followup tasks that can be done, such as removing now unneeded abstraction layers, e.g. db.sql.fake.py --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 936a354f..c1636693 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -78,7 +78,7 @@ class MediaGoblinApp(object): setup_plugins() # Set up the database - self.connection, self.db = setup_database() + self.db = setup_database() # Register themes self.theme_registry, self.current_theme = register_themes(app_config) -- cgit v1.2.3 From fd61aac7c719a875ecdcc2e43d7dcf561bc28eca Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 15 Jan 2013 16:52:22 +0100 Subject: Unbreak 301 responses The move to werkzeug routing went pretty smooth, but one thing was broken by accident: URLs without final slash result in a 301 werkzeug.routing.RequestRedirect response. We displayed it as a generic error page rather than actually sending the redirect. Do that. One thing it does though is to skip all meddlewares, which should be OK for a 301 response, but might need rework if we decide otherwise. With this, 301 responses with lacking final slash are unbroken again. Signed-off-by: Sebastian Spaeth --- mediagoblin/app.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index c1636693..10fbf4a3 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -22,6 +22,7 @@ from mediagoblin.tools.routing import endpoint_to_controller from werkzeug.wrappers import Request from werkzeug.exceptions import HTTPException, NotFound +from werkzeug.routing import RequestRedirect from mediagoblin import meddleware, __version__ from mediagoblin.tools import common, translate, template @@ -186,6 +187,9 @@ class MediaGoblinApp(object): try: found_rule, url_values = map_adapter.match(return_rule=True) request.matchdict = url_values + except RequestRedirect as response: + # Deal with 301 responses eg due to missing final slash + return response(environ, start_response) except HTTPException as exc: # Stop and render exception return render_http_exception( -- cgit v1.2.3 From e5e2c5e7aa2c882ea02ca5eaa63a1e53d15946e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Thu, 21 Feb 2013 10:48:18 +0100 Subject: removed unused import NotFound --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 10fbf4a3..607d599b 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,7 +21,7 @@ from mediagoblin.routing import get_url_map from mediagoblin.tools.routing import endpoint_to_controller from werkzeug.wrappers import Request -from werkzeug.exceptions import HTTPException, NotFound +from werkzeug.exceptions import HTTPException from werkzeug.routing import RequestRedirect from mediagoblin import meddleware, __version__ -- cgit v1.2.3 From f3f530286ff576a3120e29f734aff0b7b7fe882c Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 3 Mar 2013 02:32:03 +0100 Subject: Updated raven plugin - Added wrap_wsgi, celery_setup, celery_logging_setup hooks - Updated raven plugin docs - Updated production considerations docs - Added raven logging setup --- mediagoblin/app.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 607d599b..bb6be4d4 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -253,4 +253,7 @@ def paste_app_factory(global_config, **app_config): mgoblin_app = MediaGoblinApp(mediagoblin_config) + for callable_hook in PluginManager().get_hook_callables('wrap_wsgi'): + mgoblin_app = callable_hook(mgoblin_app) + return mgoblin_app -- cgit v1.2.3 From 5907154a593bf5fc02c1e0fbc8afe683ac7d3602 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 22 Mar 2013 18:46:47 +0100 Subject: Basic itsdangerous infrastructure. Implement the basic infrastructure for using itsdangerous in mediagoblin. Usage instructions will follow. --- mediagoblin/app.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index bb6be4d4..515b5b66 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -36,6 +36,7 @@ from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_locales, setup_workbench, setup_database, setup_storage, setup_beaker_cache) from mediagoblin.tools.pluginapi import PluginManager +from mediagoblin.tools.crypto import setup_crypto _log = logging.getLogger(__name__) @@ -66,6 +67,8 @@ class MediaGoblinApp(object): # Open and setup the config global_config, app_config = setup_global_and_app_config(config_path) + setup_crypto() + ########################################## # Setup other connections / useful objects ########################################## -- cgit v1.2.3 From c7424612d7c0447373dce8d69aa5af03aebe08dc Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sun, 24 Mar 2013 14:44:41 -0400 Subject: Back sessions with It's Dangerous. This is a contribution to #668. --- mediagoblin/app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 515b5b66..fe8e8c4b 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -25,7 +25,7 @@ from werkzeug.exceptions import HTTPException from werkzeug.routing import RequestRedirect from mediagoblin import meddleware, __version__ -from mediagoblin.tools import common, translate, template +from mediagoblin.tools import common, session, translate, template from mediagoblin.tools.response import render_http_exception from mediagoblin.tools.theme import register_themes from mediagoblin.tools import request as mg_request @@ -160,7 +160,8 @@ class MediaGoblinApp(object): ## Attach utilities to the request object # Do we really want to load this via middleware? Maybe? - request.session = request.environ['beaker.session'] + session_manager = session.SessionManager() + request.session = session_manager.load_session_from_cookie(request) # Attach self as request.app # Also attach a few utilities from request.app for convenience? request.app = self @@ -229,6 +230,8 @@ class MediaGoblinApp(object): response = render_http_exeption( request, e, e.get_description(environ)) + session_manager.save_session_to_cookie(request.session, response) + return response(environ, start_response) def __call__(self, environ, start_response): -- cgit v1.2.3 From 9e1fa2396fa4d340e3bcf01116cd1e2b6e5dee51 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sun, 24 Mar 2013 15:10:08 -0400 Subject: Remove beaker stuff from the code. This is all obsoleted by It's Dangerous. --- mediagoblin/app.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index fe8e8c4b..2c772fe1 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -34,7 +34,7 @@ from mediagoblin.init.celery import setup_celery_from_config from mediagoblin.init.plugins import setup_plugins from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_locales, setup_workbench, setup_database, - setup_storage, setup_beaker_cache) + setup_storage) from mediagoblin.tools.pluginapi import PluginManager from mediagoblin.tools.crypto import setup_crypto @@ -103,9 +103,6 @@ class MediaGoblinApp(object): # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) - # set up caching - self.cache = setup_beaker_cache() - # Setup celery, if appropriate if setup_celery and not app_config.get('celery_setup_elsewhere'): if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true': -- cgit v1.2.3 From b0ee3aae91fa49b25b84dce20931e970639d17fe Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 9 Apr 2013 22:49:11 +0200 Subject: Make session cookies more secure. 1. Our session cookies only need to be available to http, so mark them appropiately. 2. Send the cookie to the subpath for mediagoblin. And instantiate a session manager on the app, once. --- mediagoblin/app.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 2c772fe1..1137c0d7 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -73,6 +73,9 @@ class MediaGoblinApp(object): # Setup other connections / useful objects ########################################## + # Setup Session Manager, not needed in celery + self.session_manager = session.SessionManager() + # load all available locales setup_locales() @@ -157,7 +160,7 @@ class MediaGoblinApp(object): ## Attach utilities to the request object # Do we really want to load this via middleware? Maybe? - session_manager = session.SessionManager() + session_manager = self.session_manager request.session = session_manager.load_session_from_cookie(request) # Attach self as request.app # Also attach a few utilities from request.app for convenience? @@ -227,7 +230,8 @@ class MediaGoblinApp(object): response = render_http_exeption( request, e, e.get_description(environ)) - session_manager.save_session_to_cookie(request.session, response) + session_manager.save_session_to_cookie(request.session, + request, response) return response(environ, start_response) -- cgit v1.2.3 From 6a28bc4e87de920dbd97e078dc8f4876c8d52cfc Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 17 Apr 2013 10:03:33 -0500 Subject: Fixing typo in calling render_http_exception --- mediagoblin/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 1137c0d7..2c88e916 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -227,7 +227,7 @@ class MediaGoblinApp(object): for m in self.meddleware[::-1]: m.process_response(request, response) except HTTPException as e: - response = render_http_exeption( + response = render_http_exception( request, e, e.get_description(environ)) session_manager.save_session_to_cookie(request.session, -- cgit v1.2.3 From c5d8d30182731f8e689574e096f663dcf665360d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 19 Apr 2013 16:51:14 -0500 Subject: removing old callable utilities and porting stuff over. --- mediagoblin/app.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 2c88e916..bf0e0f13 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -35,7 +35,7 @@ from mediagoblin.init.plugins import setup_plugins from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_locales, setup_workbench, setup_database, setup_storage) -from mediagoblin.tools.pluginapi import PluginManager +from mediagoblin.tools.pluginapi import PluginManager, hook_transform from mediagoblin.tools.crypto import setup_crypto @@ -259,8 +259,6 @@ def paste_app_factory(global_config, **app_config): raise IOError("Usable mediagoblin config not found.") mgoblin_app = MediaGoblinApp(mediagoblin_config) - - for callable_hook in PluginManager().get_hook_callables('wrap_wsgi'): - mgoblin_app = callable_hook(mgoblin_app) + mgoblin_app = hook_transform('wrap_wsgi', mgoblin_app) return mgoblin_app -- cgit v1.2.3 From 3810309443899e92d640fb0c893018ef82b786ee Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 8 May 2013 14:35:31 -0500 Subject: The beginning of context hooks. Not the working solution, but getting there conceptually. Basically we'll have a key with the view and the template as a tuple which is the context hook that anyone can attach to. However, some changes have still to be made: - The unit test doesn't work yet and contains a set_trace ;) - We'll probably switch the "view" component from being the callable to the "urlgen"'able name per Elrond's suggestion - Found a bug in unit tests related to running custom apps for different configs... hm. I need to fix this! Nonetheless, making progress. This commit sponsored by... wait a minute... Christopher Webber?! --- mediagoblin/app.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index bf0e0f13..dc2900a9 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -201,6 +201,9 @@ class MediaGoblinApp(object): exc.get_description(environ))(environ, start_response) controller = endpoint_to_controller(found_rule) + # Make a reference to the controller on the request... + # used for lazy context modification + request.controller = controller # pass the request through our meddleware classes try: -- cgit v1.2.3 From 98dacfe67e40eb3c575b2fb9a5a80ced3e284ddc Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 10 May 2013 20:26:55 -0500 Subject: Use the controller's symbolic/lookup name as part of the key for context hooks This commit sponsored by David Collins. Thank you! --- mediagoblin/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index dc2900a9..3ebaa45b 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -201,9 +201,9 @@ class MediaGoblinApp(object): exc.get_description(environ))(environ, start_response) controller = endpoint_to_controller(found_rule) - # Make a reference to the controller on the request... + # Make a reference to the controller's symbolic name on the request... # used for lazy context modification - request.controller = controller + request.controller_name = found_rule.endpoint # pass the request through our meddleware classes try: -- cgit v1.2.3 From f7a5c7c78c6dcf3dcb3b81efbedc9a333df49fb7 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 14 May 2013 14:24:27 -0500 Subject: Fully working context hooks, both template/view and global level, with tests Needs documentation though... that's coming next :) This commit sponsored by Luca Tius. Thanks Luca! --- mediagoblin/app.py | 1 + 1 file changed, 1 insertion(+) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 3ebaa45b..1984ce77 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -188,6 +188,7 @@ class MediaGoblinApp(object): mg_request.setup_user_in_request(request) + request.controller_name = None try: found_rule, url_values = map_adapter.match(return_rule=True) request.matchdict = url_values -- cgit v1.2.3