You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by ju...@apache.org on 2013/01/15 15:57:50 UTC
svn commit: r1433448 - in
/incubator/bloodhound/branches/bep_0003_multiproduct:
bloodhound_multiproduct/multiproduct/ trac/trac/ trac/trac/web/
Author: jure
Date: Tue Jan 15 14:57:49 2013
New Revision: 1433448
URL: http://svn.apache.org/viewvc?rev=1433448&view=rev
Log:
Towards #322, #323, install global hooks from trac/__init__.py (hardcoded atm), provide EnvironmentStub replacement for tests to run properly
Modified:
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
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/__init__.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/dbcursor.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py?rev=1433448&r1=1433447&r2=1433448&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py Tue Jan 15 14:57:49 2013
@@ -16,7 +16,7 @@
# specific language governing permissions and limitations
# under the License.
-from trac.db.util import IterableCursor
+import trac.db.util
from trac.util import concurrency
import sqlparse
@@ -37,8 +37,8 @@ TRANSLATE_TABLES = ['ticket', 'enum', 'c
PRODUCT_COLUMN = 'product'
DEFAULT_PRODUCT = 'default'
-class BloodhoundIterableCursor(IterableCursor):
- __slots__ = IterableCursor.__slots__ + ['_translator']
+class BloodhoundIterableCursor(trac.db.util.IterableCursor):
+ __slots__ = trac.db.util.IterableCursor.__slots__ + ['_translator']
_tls = concurrency.ThreadLocal(env=None)
def __init__(self, cursor, log=None):
@@ -72,6 +72,9 @@ class BloodhoundIterableCursor(IterableC
def set_env(cls, env):
cls._tls.env = env
+# replace trac.db.util.IterableCursor with BloodhoundIterableCursor
+trac.db.util.IterableCursor = BloodhoundIterableCursor
+
class BloodhoundProductSQLTranslate(object):
_join_statements = ['LEFT JOIN', 'LEFT OUTER JOIN',
'RIGHT JOIN', 'RIGHT OUTER JOIN',
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=1433448&r1=1433447&r2=1433448&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 Tue Jan 15 14:57:49 2013
@@ -29,11 +29,11 @@ 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
+import trac.env
+
class Environment(trac.env.Environment):
"""Bloodhound environment manager
@@ -44,10 +44,11 @@ class Environment(trac.env.Environment):
(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
+ # global environment w/o parent, set these two before super.__init__
+ # as database access can take place within trac.env.Environment
self.parent = None
self.product = None
+ super(Environment, self).__init__(path, create=create, options=options)
@property
def db_query(self):
@@ -59,6 +60,41 @@ class Environment(trac.env.Environment):
BloodhoundIterableCursor.set_env(self)
return super(Environment, self).db_transaction
+# replace trac.env.Environment with Environment
+trac.env.Environment = Environment
+
+# this must follow the monkey patch (trac.env.Environment) above, otherwise
+# trac.test.EnvironmentStub will not be correct as the class will derive from
+# not replaced trac.env.Environment
+import trac.test
+
+class EnvironmentStub(trac.test.EnvironmentStub):
+ """Bloodhound test environment stub
+
+ This class replaces trac.test.EnvironmentStub and extends it with parent and product
+ properties (same case as with the Environment).
+ """
+ def __init__(self, default_data=False, enable=None, disable=None,
+ path=None, destroying=False):
+ self.parent = None
+ self.product = None
+ super(EnvironmentStub, self).__init__(default_data=default_data,
+ enable=enable, disable=disable,
+ path=path, destroying=destroying)
+
+ @property
+ def db_query(self):
+ BloodhoundIterableCursor.set_env(self)
+ return super(EnvironmentStub, self).db_query
+
+ @property
+ def db_transaction(self):
+ BloodhoundIterableCursor.set_env(self)
+ return super(EnvironmentStub, self).db_transaction
+
+# replace trac.test.EnvironmentStub
+trac.test.EnvironmentStub = EnvironmentStub
+
class ProductEnvironment(Component, ComponentManager):
"""Bloodhound product-aware environment manager.
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=1433448&r1=1433447&r2=1433448&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 Tue Jan 15 14:57:49 2013
@@ -15,14 +15,13 @@
# specific language governing permissions and limitations
# under the License.
-import re
+# these two imports monkey patch required classes
+import multiproduct.env
+import multiproduct.dbcursor
-from trac.hooks import EnvironmentFactoryBase, GlobalHooksBase
-import trac.env
-import trac.db.util
+import re
-from multiproduct.dbcursor import BloodhoundIterableCursor
-from multiproduct.env import Environment, ProductEnvironment
+from trac.hooks import EnvironmentFactoryBase
PRODUCT_RE = re.compile(r'^/products/(?P<pid>[^/]*)(?P<pathinfo>.*)')
@@ -36,10 +35,5 @@ class MultiProductEnvironmentFactory(Env
if m:
pid = m.group('pid')
if pid:
- env = ProductEnvironment(global_env, pid)
+ env = multiproduct.env.ProductEnvironment(global_env, pid)
return env
-
-class MultiProductGlobalHooks(GlobalHooksBase):
- def install_hooks(self, environ, env_path):
- trac.env.Environment = Environment
- trac.db.util.IterableCursor = BloodhoundIterableCursor
Modified: incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/__init__.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/__init__.py?rev=1433448&r1=1433447&r2=1433448&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/__init__.py (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/__init__.py Tue Jan 15 14:57:49 2013
@@ -17,3 +17,9 @@ try:
__version__ = get_distribution('Trac').version
except DistributionNotFound:
__version__ = '1.0'
+
+try:
+ from hooks import install_global_hooks
+ install_global_hooks()
+except:
+ pass
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=1433448&r1=1433447&r2=1433448&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/hooks.py (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/hooks.py Tue Jan 15 14:57:49 2013
@@ -28,10 +28,6 @@ class EnvironmentFactoryBase(object):
def open_environment(self, environ, env_path, global_env, use_cache=False):
return None
-class GlobalHooksBase(object):
- def install_hooks(self, environ, env_path):
- return
-
def _get_plugins_dir(env_path):
return os.path.normcase(os.path.realpath(os.path.join(env_path, 'plugins')))
@@ -57,20 +53,18 @@ def _get_hook_class(env_path, hook_path,
_global_hooks_installed = False
_global_hooks_lock = threading.Lock()
-def install_global_hooks(environ, env_path):
+def install_global_hooks():
global _global_hooks_installed, _global_hooks_lock
if _global_hooks_installed:
return
_global_hooks_lock.acquire()
try:
if not _global_hooks_installed:
- config = _get_config(env_path)
- 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)
+ try:
+ # TODO: this is currently hardcoded, maybe it could be made configurable in the future
+ import multiproduct.hooks
+ except:
+ pass
_global_hooks_installed = True
finally:
_global_hooks_lock.release()
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=1433448&r1=1433447&r2=1433448&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 Tue Jan 15 14:57:49 2013
@@ -435,8 +435,7 @@ def dispatch_request(environ, start_resp
env = env_error = None
try:
- from trac.hooks import environment_factory, install_global_hooks
- install_global_hooks(environ, env_path)
+ from trac.hooks import environment_factory
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 \