incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1432059 - in /incubator/bloodhound/branches/bep_0003_multiproduct: bloodhound_multiproduct/multiproduct/env.py bloodhound_multiproduct/multiproduct/hooks.py trac/trac/hooks.py trac/trac/web/main.py
Date Fri, 11 Jan 2013 14:20:22 GMT
Author: jure
Date: Fri Jan 11 14:20:22 2013
New Revision: 1432059

URL: http://svn.apache.org/viewvc?rev=1432059&view=rev
Log:
Towards integrating #115 and #288, still wip


Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
    incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/hooks.py
    incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/main.py

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py?rev=1432059&r1=1432058&r2=1432059&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
Fri Jan 11 14:20:22 2013
@@ -24,15 +24,41 @@ from urlparse import urlsplit
 from trac.config import ConfigSection, Option
 from trac.core import Component, ComponentManager, implements
 from trac.db.api import with_transaction
-from trac.env import Environment, ISystemInfoProvider
 from trac.util import get_pkginfo, lazy
 from trac.util.compat import sha1
 from trac.versioncontrol import RepositoryManager
 from trac.web.href import Href
 
+import trac.env
+
 from multiproduct.model import Product
 from multiproduct.dbcursor import BloodhoundIterableCursor
 
+class Environment(trac.env.Environment):
+    """Bloodhound environment manager
+
+    This class is intended as monkey-patch replacement for
+    trac.env.Environment. Required database access methods/properties
+    are replaced to provide global view of the database in contrast
+    to ProductEnvironment that features per-product view of the database
+    (in the context of selected product).
+    """
+    def __init__(self, path, create=False, options=[]):
+        super(Environment, self).__init__(path, create=create, options=options)
+        # global environment w/o parent
+        self.env = None
+        self.product = None
+
+    @property
+    def db_query(self):
+        BloodhoundIterableCursor.set_env(self)
+        return super(Environment, self).db_query
+
+    @property
+    def db_transaction(self):
+        BloodhoundIterableCursor.set_env(self)
+        return super(Environment, self).db_transaction
+
 class ProductEnvironment(Component, ComponentManager):
     """Bloodhound product-aware environment manager.
 
@@ -54,7 +80,7 @@ class ProductEnvironment(Component, Comp
     See https://issues.apache.org/bloodhound/wiki/Proposals/BEP-0003
     """
 
-    implements(ISystemInfoProvider)
+    implements(trac.env.ISystemInfoProvider)
 
     @property
     def system_info_providers(self):
@@ -197,6 +223,7 @@ class ProductEnvironment(Component, Comp
 
         self.env = env
         self.product = product
+        self.path = self.env.path
         self.systeminfo = []
         self._href = self._abs_href = None
 
@@ -208,14 +235,14 @@ class ProductEnvironment(Component, Comp
         return self.env.get_system_info()
 
     # Same as parent environment's . Avoid duplicated code
-    component_activated = Environment.component_activated.im_func
-    _component_name = Environment._component_name.im_func
-    _component_rules = Environment._component_rules
-    enable_component = Environment.enable_component.im_func
-    get_known_users = Environment.get_known_users.im_func
-    get_systeminfo = Environment.get_system_info.im_func
-    get_repository = Environment.get_repository.im_func
-    is_component_enabled = Environment.is_component_enabled.im_func
+    component_activated = trac.env.Environment.component_activated.im_func
+    _component_name = trac.env.Environment._component_name.im_func
+    _component_rules = trac.env.Environment._component_rules
+    enable_component = trac.env.Environment.enable_component.im_func
+    get_known_users = trac.env.Environment.get_known_users.im_func
+    get_systeminfo = trac.env.Environment.get_system_info.im_func
+    get_repository = trac.env.Environment.get_repository.im_func
+    is_component_enabled = trac.env.Environment.is_component_enabled.im_func
 
     def get_db_cnx(self):
         """Return a database connection from the connection pool

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py?rev=1432059&r1=1432058&r2=1432059&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
Fri Jan 11 14:20:22 2013
@@ -15,16 +15,31 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
+import re
+
 from trac.hooks import EnvironmentFactoryBase, GlobalHooksBase
 import trac.env
 import trac.db.util
+
 from multiproduct.dbcursor import BloodhoundIterableCursor
+from multiproduct.env import Environment, ProductEnvironment
+
+PRODUCT_RE = re.compile(r'^/products/(?P<pid>[^/]*)(?P<pathinfo>.*)')
 
 class MultiProductEnvironmentFactory(EnvironmentFactoryBase):
-    def open_environment(self, environ, env_path, use_cache=False):
-        return None
+    def open_environment(self, environ, env_path, global_env, use_cache=False):
+        env = pid = None
+        path_info = environ.get('PATH_INFO')
+        if not path_info:
+            return env
+        m = PRODUCT_RE.match(path_info)
+        if m:
+            pid = m.group('pid')
+        if pid:
+            env = ProductEnvironment(global_env, pid)
+        return env
 
 class MultiProductGlobalHooks(GlobalHooksBase):
     def install_hooks(self, environ, env_path):
-        # trac.env.Environment = BloodhoundEnvironment
+        trac.env.Environment = Environment
         trac.db.util.IterableCursor = BloodhoundIterableCursor

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/hooks.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/hooks.py?rev=1432059&r1=1432058&r2=1432059&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/hooks.py (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/hooks.py Fri Jan 11 14:20:22
2013
@@ -24,7 +24,7 @@ from config import Configuration
 __all__ = ['environment_factory', 'install_global_hooks']
 
 class EnvironmentFactoryBase(object):
-    def open_environment(self, environ, env_path, use_cache=False):
+    def open_environment(self, environ, env_path, global_env, use_cache=False):
         return None
 
 class GlobalHooksBase(object):
@@ -48,21 +48,21 @@ def _hook_load(env_path, hook_path):
 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):
-        if issubclass(cls, class_type):
+        if issubclass(cls, class_type) and \
+           not cls is class_type:
             return cls
     return None
 
-def environment_factory(environ, env_path):
-    config = _get_config(env_path)
-    hook_path = config.get('hooks', 'environment_factory', default=None)
-    return _get_hook_class(env_path, hook_path, EnvironmentFactoryBase) if hook_path else
None
-
 def install_global_hooks(environ, env_path):
     config = _get_config(env_path)
-    hook_paths = config.get('hooks', 'global_hooks', default=None)
+    hook_paths = config.get('trac', 'global_hooks', default=None)
     if hook_paths:
         for hook_path in hook_paths.split(','):
             cls = _get_hook_class(env_path, hook_path, GlobalHooksBase)
             if cls:
                 cls().install_hooks(environ, env_path)
     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

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/main.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/main.py?rev=1432059&r1=1432058&r2=1432059&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/main.py (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/main.py Fri Jan 11 14:20:22
2013
@@ -437,9 +437,11 @@ def dispatch_request(environ, start_resp
     try:
         from trac.hooks import environment_factory, install_global_hooks
         install_global_hooks(environ, env_path)
-        factory = environment_factory(environ, env_path)
-        env = factory().open_environment(environ, env_path, use_cache=not run_once) if factory
\
-                else open_environment(env_path, use_cache=not run_once)
+        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
+        env = factory_env if factory_env else global_env
         if env.base_url_for_redirect:
             environ['trac.base_url'] = env.base_url
 



Mime
View raw message