Added tests for HTTP callbacks
[mediagoblin.git] / mediagoblin / app.py
index b7ca092d2345b32d42188261059cb251ae681482..51f5899a0538be7bf42417fd65b4c94798475302 100644 (file)
@@ -24,12 +24,15 @@ 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
+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 PluginManager
 
 
 _log = logging.getLogger(__name__)
@@ -52,6 +55,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
         ##############
@@ -63,18 +67,29 @@ 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()
 
+        # Register themes
+        self.theme_registry, self.current_theme = register_themes(app_config)
+
         # Get the template environment
         self.template_loader = get_jinja_loader(
-            app_config.get('local_templates'))
+            app_config.get('local_templates'),
+            self.current_theme,
+            PluginManager().get_template_paths()
+            )
 
         # Set up storage systems
         self.public_store, self.queue_store = setup_storage()
 
         # set up routing
-        self.routing = routing.get_mapper()
+        self.routing = routing.get_mapper(PluginManager().get_routes())
 
         # set up staticdirector tool
         self.staticdirector = get_staticdirector(app_config)
@@ -84,7 +99,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)
@@ -167,7 +182,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: