Author: jure
Date: Thu Jan 10 13:38:13 2013
New Revision: 1431351
URL: http://svn.apache.org/viewvc?rev=1431351&view=rev
Log:
Towards integrating #115 and #288, still wip
Added:
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
- copied, changed from r1430286,
incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/bloodhound/db.py
Removed:
incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/bloodhound/
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/web/standalone.py
Copied:
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
(from r1430286,
incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/bloodhound/db.py)
URL:
http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py?p2=incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py&p1=incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/bloodhound/db.py&r1=1430286&r2=1431351&rev=1431351&view=diff
==============================================================================
---
incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/bloodhound/db.py
(original)
+++
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
Thu Jan 10 13:38:13 2013
@@ -35,6 +35,7 @@ SKIP_TABLES = ['system', 'permission', '
]
TRANSLATE_TABLES = ['ticket', 'enum', 'component', 'milestone', 'version',
'wiki']
PRODUCT_COLUMN = 'product'
+DEFAULT_PRODUCT = 'default'
class BloodhoundIterableCursor(IterableCursor):
__slots__ = IterableCursor.__slots__ + ['_translator']
@@ -47,16 +48,15 @@ class BloodhoundIterableCursor(IterableC
@property
def translator(self):
if not self._translator:
- from env import DEFAULT_PRODUCT
- product = self.env.product_scope if self.env else DEFAULT_PRODUCT
+ product_prefix = self.env.product.prefix if (self.env and
self.env.product) else DEFAULT_PRODUCT
self._translator = BloodhoundProductSQLTranslate(SKIP_TABLES,
TRANSLATE_TABLES,
PRODUCT_COLUMN,
- product)
+ product_prefix)
return self._translator
def _translate_sql(self, sql):
- return self.translator.translate(sql) if (self.env and not
self.env.product_aware) else sql
+ return self.translator.translate(sql) if (self.env and
self.env.product) else sql
def execute(self, sql, args=None):
return super(BloodhoundIterableCursor,
self).execute(self._translate_sql(sql), args=args)
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=1431351&r1=1431350&r2=1431351&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
Thu Jan 10 13:38:13 2013
@@ -19,15 +19,19 @@
"""Bloodhound product environment and related APIs"""
import os.path
+from urlparse import urlsplit
from trac.config import ConfigSection, Option
-from trac.core import Component, ComponentManager, ExtensionPoint, \
- implements, TracError
+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
from multiproduct.model import Product
+from multiproduct.dbcursor import BloodhoundIterableCursor
class ProductEnvironment(Component, ComponentManager):
"""Bloodhound product-aware environment manager.
@@ -232,9 +236,8 @@ class ProductEnvironment(Component, Comp
with env.db_query as db:
...
"""
- # TODO: Install database schema proxy with limited scope (see #288)
- #return DatabaseManager(self).get_connection()
- raise NotImplementedError
+ # share connection pool with global environment
+ return self.env.get_db_cnx()
@lazy
def db_exc(self):
@@ -251,21 +254,19 @@ class ProductEnvironment(Component, Comp
except env.db_exc.IntegrityError, e:
...
"""
- return DatabaseManager(self).get_exceptions()
+ # exception types same as in global environment
+ return self.env.db_exc()
def with_transaction(self, db=None):
"""Decorator for transaction functions :deprecated:"""
- # TODO: What shall we do ?
- #return with_transaction(self, db)
- raise NotImplementedError
+ return with_transaction(self, db)
def get_read_db(self):
"""Return a database connection for read purposes :deprecated:
See `trac.db.api.get_read_db` for detailed documentation."""
- # TODO: Install database schema proxy with limited scope (see #288)
- #return DatabaseManager(self).get_connection(readonly=True)
- raise NotImplementedError
+ # database connection is shared with global environment
+ return self.env.get_read_db()
@property
def db_query(self):
@@ -299,9 +300,8 @@ class ProductEnvironment(Component, Comp
context was the outermost context (`db_query` or
`db_transaction`).
"""
- # TODO: Install database schema proxy with limited scope (see #288)
- #return QueryContextManager(self)
- raise NotImplementedError
+ BloodhoundIterableCursor.set_env(self)
+ return self.env.db_query
@property
def db_transaction(self):
@@ -336,9 +336,8 @@ class ProductEnvironment(Component, Comp
context, if this context was the outermost context
(`db_query` or `db_transaction`).
"""
- # TODO: Install database schema proxy with limited scope (see #288)
- #return TransactionContextManager(self)
- raise NotImplementedError
+ BloodhoundIterableCursor.set_env(self)
+ return self.env.db_transaction
def shutdown(self, tid=None):
"""Close the environment."""
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=1431351&r1=1431350&r2=1431351&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
Thu Jan 10 13:38:13 2013
@@ -16,6 +16,9 @@
# under the License.
from trac.hooks import EnvironmentFactoryBase, GlobalHooksBase
+import trac.env
+import trac.db.util
+from multiproduct.dbcursor import BloodhoundIterableCursor
class MultiProductEnvironmentFactory(EnvironmentFactoryBase):
def open_environment(self, environ, env_path, use_cache=False):
@@ -23,4 +26,5 @@ class MultiProductEnvironmentFactory(Env
class MultiProductGlobalHooks(GlobalHooksBase):
def install_hooks(self, environ, env_path):
- return
+ # trac.env.Environment = BloodhoundEnvironment
+ trac.db.util.IterableCursor = BloodhoundIterableCursor
Modified:
incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/standalone.py
URL:
http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/standalone.py?rev=1431351&r1=1431350&r2=1431351&view=diff
==============================================================================
---
incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/standalone.py
(original)
+++
incubator/bloodhound/branches/bep_0003_multiproduct/trac/trac/web/standalone.py
Thu Jan 10 13:38:13 2013
@@ -120,9 +120,6 @@ class TracHTTPRequestHandler(WSGIRequest
class TracHTTP11RequestHandler(TracHTTPRequestHandler):
protocol_version = 'HTTP/1.1'
-from trac.bloodhound.env import bloodhound_hooks
-bloodhound_hooks()
-
def main():
from optparse import OptionParser, OptionValueError
parser = OptionParser(usage='usage: %prog [options] [projenv] ...',