[repository] enabled sources refactoring: to avoid error, we should always have all known source in repo.sources_by_uri and only enabled ones in repo.sources, so we still have access to the definition of temporarily disabled sources stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 20 Aug 2010 08:21:15 +0200
branchstable
changeset 6126 aca6a2c357fd
parent 6125 46b9cbbc1e37
child 6127 747e423093fc
[repository] enabled sources refactoring: to avoid error, we should always have all known source in repo.sources_by_uri and only enabled ones in repo.sources, so we still have access to the definition of temporarily disabled sources
server/__init__.py
server/repository.py
server/serverconfig.py
--- a/server/__init__.py	Fri Aug 20 08:17:04 2010 +0200
+++ b/server/__init__.py	Fri Aug 20 08:21:15 2010 +0200
@@ -131,11 +131,9 @@
     config.creating = True
     config.consider_user_state = False
     config.set_language = False
-    # only enable the system source at initialization time + admin which is not
-    # an actual source but contains initial manager account information
-    config.enabled_sources = ('system', 'admin')
+    # only enable the system source at initialization time
+    config.enabled_sources = ('system',)
     repo = Repository(config, vreg=vreg)
-    assert len(repo.sources) == 1, repo.sources
     schema = repo.schema
     sourcescfg = config.sources()
     _title = '-> creating tables '
--- a/server/repository.py	Fri Aug 20 08:17:04 2010 +0200
+++ b/server/repository.py	Fri Aug 20 08:21:15 2010 +0200
@@ -135,7 +135,8 @@
                 continue
             source = self.get_source(uri, source_config)
             self.sources_by_uri[uri] = source
-            self.sources.append(source)
+            if config.source_enabled(uri):
+                self.sources.append(source)
         self.system_source = self.sources_by_uri['system']
         # ensure system source is the first one
         self.sources.remove(self.system_source)
@@ -234,7 +235,9 @@
         else:
             self.vreg._set_schema(schema)
         self.querier.set_schema(schema)
-        for source in self.sources:
+        # don't use self.sources, we may want to give schema even to disabled
+        # sources
+        for source in self.sources_by_uri.values():
             source.set_schema(schema)
         self.schema = schema
 
--- a/server/serverconfig.py	Fri Aug 20 08:17:04 2010 +0200
+++ b/server/serverconfig.py	Fri Aug 20 08:21:15 2010 +0200
@@ -227,11 +227,7 @@
 
     # list of enables sources when sources restriction is necessary
     # (eg repository initialization at least)
-    _enabled_sources = None
-    @wproperty
-    def enabled_sources(self, sourceuris=None):
-        self._enabled_sources = sourceuris
-        clear_cache(self, 'sources')
+    enabled_sources = None
 
     def bootstrap_cubes(self):
         from logilab.common.textutils import splitstrip
@@ -266,11 +262,10 @@
         """return a dictionnaries containing sources definitions indexed by
         sources'uri
         """
-        allsources = self.read_sources_file()
-        if self._enabled_sources is None:
-            return allsources
-        return dict((uri, config) for uri, config in allsources.items()
-                    if uri in self._enabled_sources or uri == 'admin')
+        return self.read_sources_file()
+
+    def source_enabled(self, uri):
+        return not self.enabled_sources or uri in self.enabled_sources
 
     def write_sources_file(self, sourcescfg):
         sourcesfile = self.sources_file()
@@ -325,8 +320,7 @@
             for uri in sources:
                 assert uri in known_sources, uri
             enabled_sources = sources
-        self._enabled_sources = enabled_sources
-        clear_cache(self, 'sources')
+        self.enabled_sources = enabled_sources
 
     def migration_handler(self, schema=None, interactive=True,
                           cnx=None, repo=None, connect=True, verbosity=None):