Commits

Anonymous committed cfa8622 Draft

#441, lookup custom web bootstrap handler, patch t441_r1468583_bootstrap_handler_lookup.diff applied (from Olemis)

git-svn-id: https://svn.apache.org/repos/asf/bloodhound/trunk@146919913f79535-47bb-0310-9956-ffa450edef68

  • Participants
  • Parent commits e8093ba

Comments (0)

Files changed (2)

File trac/trac/hooks.py

         return factory().create_request(env, environ, start_response) if factory \
                 else RequestWithSession(environ, start_response)
 
+default_bootstrap_handler = DefaultBootstrapHandler()
+
 # Recursive imports
 from trac.web.main import send_project_index, get_environments

File trac/trac/web/main.py

 
 _slashes_re = re.compile(r'/+')
 
-def dispatch_request(environ, start_response):
+def dispatch_request(environ, start_response, bootstrap=None):
     """Main entry point for the Trac web interface.
 
     :param environ: the WSGI environment dict
     :param start_response: the WSGI callback for starting the response
+    :param bootstrap: handler responsible for environment lookup and
+                      instantiating request objects
     """
 
     # SCRIPT_URL is an Apache var containing the URL before URL rewriting
     environ.setdefault('trac.locale', '')
     environ.setdefault('trac.base_url',
                        os.getenv('TRAC_BASE_URL'))
-
+    environ.setdefault('trac.bootstrap_handler',
+                       os.getenv('TRAC_BOOTSTRAP_HANDLER'))
 
     locale.setlocale(locale.LC_ALL, environ['trac.locale'])
 
-    # FIXME: Load custom bootstrap handler
-    from trac.hooks import DefaultBootstrapHandler
-    bootstrap = DefaultBootstrapHandler()
+    if bootstrap is None:
+        bootstrap_ep = environ['trac.bootstrap_handler']
+        if bootstrap_ep:
+            from pkg_resources import EntryPoint
+            try:
+                ep = EntryPoint.parse('x = ' + bootstrap_ep)
+                bootstrap = ep.load(require=False)
+            except Exception, e:
+                log = environ.get('wsgi.errors')
+                if log:
+                    log.write("[FAIL] [Trac] entry point '%s'. Reason %s" %
+                              (bootstrap_ep, repr(exception_to_unicode(e))))
+    if bootstrap is None:
+        from trac.hooks import default_bootstrap_handler
+        bootstrap = default_bootstrap_handler
 
     # Determine the environment