incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1454305 - in /incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct: multiproduct/api.py multiproduct/env.py tests/env.py
Date Fri, 08 Mar 2013 09:45:46 GMT
Author: jure
Date: Fri Mar  8 09:45:45 2013
New Revision: 1454305

URL: http://svn.apache.org/r1454305
Log:
Only enable SQL translator after schema has been upgraded to multiproduct, related to #406,
#407


Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py?rev=1454305&r1=1454304&r2=1454305&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py
Fri Mar  8 09:45:45 2013
@@ -114,7 +114,10 @@ class MultiProductSystem(Component):
             this version of the %s (%d).''' % (db_installed_version,
                                                PLUGIN_NAME,
                                                DB_VERSION))
-        return db_installed_version < DB_VERSION
+        needs_upgrade = db_installed_version < DB_VERSION
+        if not needs_upgrade:
+            self.env.enable_multiproduct_schema(True)
+        return needs_upgrade
 
     def _update_db_version(self, db, version):
         old_version = self.get_version()
@@ -277,6 +280,8 @@ class MultiProductSystem(Component):
                     db(statement)
                 db_installed_version = self._update_db_version(db, 4)
 
+            self.env.enable_multiproduct_schema(True)
+
     # ITemplateProvider methods
     def get_templates_dirs(self):
         """provide the plugin templates"""

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=1454305&r1=1454304&r2=1454305&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 Mar  8 09:45:45 2013
@@ -82,6 +82,8 @@ class Environment(trac.env.Environment):
         self.systeminfo = []
         self._href = self._abs_href = None
 
+        self._multiproduct_schema_enabled = False
+
         if create:
             self.create(options)
         else:
@@ -100,13 +102,18 @@ class Environment(trac.env.Environment):
                 with ComponentEnvironmentContext(self, participant):
                     participant.environment_created()
 
+        if not self._multiproduct_schema_enabled:
+            self.log.warn("Running environment schema not upgraded to multi-product")
+
     @property
     def db_query(self):
-        return ProductEnvContextManager(super(Environment, self).db_query, self)
+        return ProductEnvContextManager(super(Environment, self).db_query, self) \
+            if self._multiproduct_schema_enabled else self.db_direct_query
 
     @property
     def db_transaction(self):
-        return ProductEnvContextManager(super(Environment, self).db_transaction, self)
+        return ProductEnvContextManager(super(Environment, self).db_transaction, self) \
+            if self._multiproduct_schema_enabled else self.db_direct_transaction
 
     @property
     def db_direct_query(self):
@@ -218,6 +225,9 @@ class Environment(trac.env.Environment):
                 """ % ('initial_' if initial else ''))
         return rows and int(rows[0][0])
 
+    def enable_multiproduct_schema(self, enable=True):
+        self._multiproduct_schema_enabled = enable
+
 # replace trac.env.Environment with Environment
 trac.env.Environment = Environment
 
@@ -255,8 +265,9 @@ class EnvironmentStub(trac.test.Environm
                  path=None, destroying=False):
         self.parent = None
         self.product = None
-        self.mpsystem = None
-        self._db_direct = False
+
+        self._multiproduct_schema_enabled = False
+
         super(EnvironmentStub, self).__init__(default_data=False,
                                               enable=enable, disable=disable,
                                               path=path, destroying=destroying)
@@ -300,18 +311,12 @@ class EnvironmentStub(trac.test.Environm
         #env.config.save()
 
     def reset_db(self, default_data=None):
-        self._db_direct = True
-        super(EnvironmentStub, self).reset_db(default_data=default_data)
-        self._db_direct = False
-
-    @property
-    def db_query(self):
-        return super(EnvironmentStub, self).db_query if not self._db_direct else self.db_direct_query
-
-    @property
-    def db_transaction(self):
-        return super(EnvironmentStub, self).db_transaction if not self._db_direct else self.db_direct_transaction
-
+        multiproduct_schema = self._multiproduct_schema_enabled
+        self._multiproduct_schema_enabled = False
+        try:
+            super(EnvironmentStub, self).reset_db(default_data=default_data)
+        finally:
+            self._multiproduct_schema_enabled = multiproduct_schema
 
 # replace trac.test.EnvironmentStub
 trac.test.EnvironmentStub = EnvironmentStub

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py?rev=1454305&r1=1454304&r2=1454305&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
Fri Mar  8 09:45:45 2013
@@ -196,6 +196,9 @@ class MultiproductTestCase(unittest.Test
         except OperationalError:
             # table remains but database version is deleted
             pass
+        # assume that the database schema has been upgraded, enable
+        # multi-product schema support in environment
+        env.enable_multiproduct_schema(True)
 
     def _load_default_data(self, env):
         r"""Initialize environment with default data by respecting



Mime
View raw message