incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1454383 - in /incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct: dbcursor.py env.py
Date Fri, 08 Mar 2013 13:38:30 GMT
Author: jure
Date: Fri Mar  8 13:38:29 2013
New Revision: 1454383

URL: http://svn.apache.org/r1454383
Log:
#407, make setup work again, properly setup environment


Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.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=1454383&r1=1454382&r2=1454383&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
Fri Mar  8 13:38:29 2013
@@ -94,6 +94,10 @@ class BloodhoundIterableCursor(trac.db.u
     def get_env(cls):
         return cls._tls.env
 
+    @classmethod
+    def cache_reset(cls):
+        translate_sql.clear()
+
 # replace trac.db.util.IterableCursor with BloodhoundIterableCursor
 trac.db.util.IterableCursor = BloodhoundIterableCursor
 

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=1454383&r1=1454382&r2=1454383&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 13:38:29 2013
@@ -32,7 +32,7 @@ from trac.web.href import Href
 
 from multiproduct.api import MultiProductSystem, ISupportMultiProductEnvironment
 from multiproduct.config import Configuration
-from multiproduct.dbcursor import ProductEnvContextManager, BloodhoundConnectionWrapper
+from multiproduct.dbcursor import ProductEnvContextManager, BloodhoundConnectionWrapper,
BloodhoundIterableCursor
 from multiproduct.model import Product
 
 import trac.env
@@ -98,13 +98,13 @@ class Environment(trac.env.Environment):
         # invoke `IEnvironmentSetupParticipant.environment_created` for all
         # global setup participants
         if create:
-            for participant in self._global_setup_participants:
+            # when creating environment, run global setup participants if schema has been
upgraded
+            # to multi-product. If not, run setup participants ...
+            for participant in self._global_setup_participants if self._multiproduct_schema_enabled
\
+                                                                   else self.setup_participants:
                 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) \
@@ -123,6 +123,9 @@ class Environment(trac.env.Environment):
     def db_direct_transaction(self):
         return ProductEnvContextManager(super(Environment, self).db_transaction)
 
+    def _all_product_envs(self):
+        return [ProductEnvironmentFactory(self, product) for product in Product.select(self)]
+
     def needs_upgrade(self):
         """Return whether the environment needs to be upgraded."""
         def needs_upgrade_in_env_list(env_list, participants):
@@ -142,9 +145,12 @@ class Environment(trac.env.Environment):
                                 return True
         if needs_upgrade_in_env_list([self], self._global_setup_participants):
             return True
-        product_envs = [self] + [ProductEnvironmentFactory(self, product) for product in
Product.select(self)]
-        if needs_upgrade_in_env_list(product_envs, self._product_setup_participants):
-            return True
+        # until schema is multi product aware, product environments can't (and shouldn't)
be
+        # instantiated
+        if self._multiproduct_schema_enabled:
+            product_envs = [self] + self._all_product_envs()
+            if needs_upgrade_in_env_list(product_envs, self._product_setup_participants):
+                return True
         return False
 
     def upgrade(self, backup=False, backup_dest=None):
@@ -174,7 +180,7 @@ class Environment(trac.env.Environment):
             return upgraders
 
         def upgraders_for_product_envs():
-            product_envs = [self] + [ProductEnvironmentFactory(self, product) for product
in Product.select(self)]
+            product_envs = [self] + self._all_product_envs()
             return upgraders_for_env_list(product_envs, self._product_setup_participants)
 
         # first enumerate components that are multi product aware and require upgrade
@@ -223,33 +229,15 @@ class Environment(trac.env.Environment):
         rows = self.db_direct_query("""
                 SELECT value FROM system WHERE name='%sdatabase_version'
                 """ % ('initial_' if initial else ''))
-        return rows and int(rows[0][0])
+        return (rows and int(rows[0][0])) or 0
 
     def enable_multiproduct_schema(self, enable=True):
         self._multiproduct_schema_enabled = enable
+        BloodhoundIterableCursor.cache_reset()
 
 # replace trac.env.Environment with Environment
 trac.env.Environment = Environment
 
-class EnvironmentSetup(trac.env.EnvironmentSetup):
-
-    def environment_created(self):
-        """Insert default data into the database.
-
-        This code is copy pasted from trac.env.EnvironmentSetup with a slight change
-        of using direct (non-translated) transaction to setup default data.
-        """
-        from trac import db_default
-        with self.env.db_direct_transaction as db:
-            for table, cols, vals in db_default.get_data(db):
-                db.executemany("INSERT INTO %s (%s) VALUES (%s)"
-                               % (table, ','.join(cols), ','.join(['%s' for c in cols])),
-                                  vals)
-        self._update_sample_config()
-
-# replace trac.env.EnvironmentSetup with EnvironmentSetup
-trac.env.EnvironmentSetup = EnvironmentSetup
-
 # 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



Mime
View raw message