Olemis Lang avatar Olemis Lang committed 219a537

BH Multiproduct #441 : Load bootstrap handler based on entry point config

Comments (0)

Files changed (2)

 t441/t441_r1468583_trac_bootstrap_handler.diff
+t441/t441_r1468583_bootstrap_handler_lookup.diff
 #t441/t441_r1452788_product_dispatch.diff
 #t441/t441_r1461631_product_module_pathinfo.diff
 #t441/t441_r1462483_product_module_testing.diff

t441/t441_r1468583_bootstrap_handler_lookup.diff

+# HG changeset patch
+# Parent a7a01d3acfdf18b7d821fda81b3796d827fb2a9b
+BH Multiproduct #441 : Lookup custom web bootstrap handler
+
+diff -r a7a01d3acfdf trac/trac/hooks.py
+--- a/trac/trac/hooks.py	Wed Apr 17 12:08:53 2013 -0500
++++ b/trac/trac/hooks.py	Wed Apr 17 17:11:37 2013 -0500
+@@ -220,5 +220,7 @@
+         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
+diff -r a7a01d3acfdf trac/trac/web/main.py
+--- a/trac/trac/web/main.py	Wed Apr 17 12:08:53 2013 -0500
++++ b/trac/trac/web/main.py	Wed Apr 17 17:11:37 2013 -0500
+@@ -342,11 +342,13 @@
+ 
+ _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
+@@ -375,13 +377,26 @@
+     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
+     
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.