diff options
Diffstat (limited to 'mediagoblin/app.py')
-rw-r--r-- | mediagoblin/app.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 0f25a4e5..ce4b0bec 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 @@ -93,7 +94,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 :) @@ -103,7 +104,6 @@ class MediaGoblinApp(object): self.middleware = [common.import_component(m)(self) for m in middleware.ENABLED_MIDDLEWARE] - def __call__(self, environ, start_response): request = Request(environ) @@ -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) @@ -150,7 +161,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 @@ -166,6 +177,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 |