You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by rj...@apache.org on 2014/04/02 06:44:02 UTC

svn commit: r1583876 - in /bloodhound/trunk: bloodhound_multiproduct/multiproduct/hooks.py trac/trac/hooks.py

Author: rjollos
Date: Wed Apr  2 04:44:01 2014
New Revision: 1583876

URL: http://svn.apache.org/r1583876
Log:
0.8dev: Fixed missing import. PEP-0008 changes.

Modified:
    bloodhound/trunk/bloodhound_multiproduct/multiproduct/hooks.py
    bloodhound/trunk/trac/trac/hooks.py

Modified: bloodhound/trunk/bloodhound_multiproduct/multiproduct/hooks.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/multiproduct/hooks.py?rev=1583876&r1=1583875&r2=1583876&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/multiproduct/hooks.py (original)
+++ bloodhound/trunk/bloodhound_multiproduct/multiproduct/hooks.py Wed Apr  2 04:44:01 2014
@@ -19,22 +19,22 @@
 
 # these imports monkey patch classes required to enable
 # multi product support
-import multiproduct.env
-import multiproduct.dbcursor
-import multiproduct.versioncontrol
-import multiproduct.ticket.query
-import multiproduct.ticket.batch
 
 import re
 
-from trac.core import TracError
 from trac.hooks import EnvironmentFactoryBase, RequestFactoryBase
-from trac.perm import PermissionCache
 from trac.web.href import Href
 from trac.web.main import RequestWithSession
 
+import multiproduct.env
+import multiproduct.dbcursor
+import multiproduct.ticket.batch
+import multiproduct.ticket.query
+import multiproduct.versioncontrol
+
 PRODUCT_RE = re.compile(r'^/products(?:/(?P<pid>[^/]*)(?P<pathinfo>.*))?')
 
+
 class MultiProductEnvironmentFactory(EnvironmentFactoryBase):
     def open_environment(self, environ, env_path, global_env, use_cache=False):
         environ.setdefault('SCRIPT_NAME', '')  # bh:ticket:594
@@ -78,19 +78,9 @@ class MultiProductEnvironmentFactory(Env
 
 
 class ProductizedHref(Href):
-    PATHS_NO_TRANSFORM = ['chrome',
-                          'login',
-                          'logout',
-                          'prefs',
-                          'products',
-                          'verify_email',
-                          'reset_password',
-                          'register',
-                          ]
-    STATIC_PREFIXES = ['js/',
-                       'css/',
-                       'img/',
-                       ]
+    PATHS_NO_TRANSFORM = ['chrome', 'login', 'logout', 'prefs', 'products',
+                          'register',  'reset_password', 'verify_email']
+    STATIC_PREFIXES = ['css/', 'img/', 'js/']
 
     def __init__(self, global_href, base):
         self.super = super(ProductizedHref, self)
@@ -120,4 +110,4 @@ class ProductRequestWithSession(RequestW
 class ProductRequestFactory(RequestFactoryBase):
     def create_request(self, env, environ, start_response):
         return ProductRequestWithSession(env, environ, start_response) \
-            if env else RequestWithSession(environ, start_response)
+               if env else RequestWithSession(environ, start_response)

Modified: bloodhound/trunk/trac/trac/hooks.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/trac/trac/hooks.py?rev=1583876&r1=1583875&r2=1583876&view=diff
==============================================================================
--- bloodhound/trunk/trac/trac/hooks.py (original)
+++ bloodhound/trunk/trac/trac/hooks.py Wed Apr  2 04:44:01 2014
@@ -15,37 +15,41 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-import os
 import imp
 import inspect
-
+import os
 import pkg_resources
 
 from trac.config import Configuration
 from trac.env import open_environment
+from trac.util import exception_to_unicode
 from trac.util.concurrency import threading
 from trac.web.api import RequestDone
 from trac.web.href import Href
 from trac.web.main import RequestWithSession
 
-
 __all__ = ['environment_factory', 'install_global_hooks']
 
+
 class EnvironmentFactoryBase(object):
     def open_environment(self, environ, env_path, global_env, use_cache=False):
         raise NotImplementedError("Must override method 'open_environment'")
 
+
 class RequestFactoryBase(object):
     def create_request(self, env, environ, start_response):
         raise NotImplementedError("Must override method 'create_request'")
 
+
 def _get_plugins_dir(env_path):
     return os.path.normcase(os.path.realpath(os.path.join(env_path, 'plugins')))
 
+
 def _get_config(env_path):
     return Configuration(os.path.join(env_path, 'conf', 'trac.ini'),
                          {'envname': os.path.basename(env_path)})
 
+
 def _hook_load(env_path, hook_path):
     hook_name = os.path.basename(hook_path[:-3])
     plugins_dir = _get_plugins_dir(env_path)
@@ -53,6 +57,7 @@ def _hook_load(env_path, hook_path):
     module = imp.load_source(hook_name, load_path)
     return module
 
+
 def _get_hook_class(env_path, hook_path, class_type):
     module = _hook_load(env_path, hook_path)
     for (name, cls) in inspect.getmembers(module, inspect.isclass):
@@ -64,6 +69,7 @@ def _get_hook_class(env_path, hook_path,
 _global_hooks_installed = False
 _global_hooks_lock = threading.Lock()
 
+
 def install_global_hooks():
     global _global_hooks_installed, _global_hooks_lock
     if _global_hooks_installed:
@@ -72,7 +78,8 @@ def install_global_hooks():
     try:
         if not _global_hooks_installed:
             try:
-                # TODO: this is currently hardcoded, maybe it could be made configurable in the future
+                # TODO: this is currently hardcoded, maybe it could be made
+                # configurable in the future
                 import multiproduct.hooks
             except:
                 pass
@@ -81,13 +88,18 @@ def install_global_hooks():
         _global_hooks_lock.release()
     return
 
+
 def environment_factory(env):
     hook_path = env.config.get('trac', 'environment_factory', default=None)
-    return _get_hook_class(env.path, hook_path, EnvironmentFactoryBase) if hook_path else None
+    return _get_hook_class(env.path, hook_path, EnvironmentFactoryBase) \
+           if hook_path else None
+
 
 def request_factory(env):
     hook_path = env.config.get('trac', 'request_factory', default=None)
-    return _get_hook_class(env.path, hook_path, RequestFactoryBase) if hook_path else None
+    return _get_hook_class(env.path, hook_path, RequestFactoryBase) \
+           if hook_path else None
+
 
 class BootstrapHandlerBase(object):
     """Objects responsible for loading the target environment and
@@ -137,8 +149,8 @@ class BootstrapHandlerBase(object):
         resulting environment object. This approach is generic but not
         efficient. Should be overridden whenever possible. 
         """
-        # If the expected configuration keys aren't found in the WSGI environment,
-        # try looking them up in the process environment variables
+        # If the expected configuration keys aren't found in the WSGI
+        # environment, try looking them up in the process environment variables
         environ.setdefault('trac.env_path', os.getenv('TRAC_ENV'))
         environ.setdefault('trac.env_parent_dir',
                            os.getenv('TRAC_ENV_PARENT_DIR'))
@@ -206,8 +218,8 @@ class DefaultBootstrapHandler(BootstrapH
                 env_name = path_info.pop(0)
     
                 if not env_name:
-                    # No specific environment requested, so render an environment
-                    # index page
+                    # No specific environment requested, so render an
+                    # environment index page
                     send_project_index(environ, start_response, env_parent_dir,
                                        env_paths)
                     raise RequestDone
@@ -215,9 +227,10 @@ class DefaultBootstrapHandler(BootstrapH
                 environ['trac.env_name'] = env_name
                 errmsg = None
     
-                # To make the matching patterns of request handlers work, we append
-                # the environment name to the `SCRIPT_NAME` variable, and keep only
-                # the remaining path in the `PATH_INFO` variable.
+                # To make the matching patterns of request handlers work, we
+                # append the environment name to the `SCRIPT_NAME` variable,
+                # and keep only the remaining path in the `PATH_INFO`
+                # variable.
                 script_name = environ.get('SCRIPT_NAME', '')
                 try:
                     script_name = unicode(script_name, 'utf-8')
@@ -237,26 +250,31 @@ class DefaultBootstrapHandler(BootstrapH
     
                 if errmsg:
                     write = start_response('404 Not Found',
-                                   [('Content-Type', 'text/plain'),
-                                    ('Content-Length', str(len(errmsg)))])
+                                           [('Content-Type', 'text/plain'),
+                                            ('Content-Length',
+                                             str(len(errmsg)))])
                     write(errmsg)
                     raise RequestDone
     
         if not env_path:
             raise EnvironmentError('The environment options "TRAC_ENV" or '
                                    '"TRAC_ENV_PARENT_DIR" or the mod_python '
-                                   'options "TracEnv" or "TracEnvParentDir" are '
-                                   'missing. Trac requires one of these options '
-                                   'to locate the Trac environment(s).')
+                                   'options "TracEnv" or "TracEnvParentDir" '
+                                   'are missing. Trac requires one of these '
+                                   'options to locate the Trac '
+                                   'environment(s).')
         run_once = environ['wsgi.run_once']
     
         env = None
         self.global_env = global_env = None
         try:
-            self.global_env = global_env = open_environment(env_path, use_cache=not run_once)
+            self.global_env = global_env = \
+                open_environment(env_path, use_cache=not run_once)
             factory = environment_factory(global_env)
-            factory_env = factory().open_environment(environ, env_path, global_env, use_cache=not run_once) if factory \
-                            else None
+            factory_env = \
+                factory().open_environment(environ, env_path, global_env,
+                                           use_cache=not run_once) \
+                if factory else None
             env = factory_env if factory_env else global_env
         except Exception:
             raise
@@ -268,11 +286,12 @@ class DefaultBootstrapHandler(BootstrapH
             factory = request_factory(self.global_env)
         except Exception:
             pass
-        return factory().create_request(env, environ, start_response) if factory \
-                else RequestWithSession(environ, start_response)
+        return factory().create_request(env, environ, start_response) \
+               if factory else RequestWithSession(environ, start_response)
 
 default_bootstrap_handler = DefaultBootstrapHandler()
 
+
 def load_bootstrap_handler(bootstrap_ep, log=None):
     """Load handler for environment lookup and instantiation of request objects