[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 26 Mar 2010 15:53:07 +0100
branchstable
changeset 5043 fe52dd3936cf
parent 5042 cc062bb09abb
child 5044 1d9bef4a2b0c
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
cwconfig.py
cwctl.py
devtools/__init__.py
goa/goaconfig.py
server/__init__.py
server/migractions.py
server/repository.py
server/serverconfig.py
server/serverctl.py
--- a/cwconfig.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/cwconfig.py	Fri Mar 26 15:53:07 2010 +0100
@@ -669,8 +669,6 @@
 
     # for some commands (creation...) we don't want to initialize gettext
     set_language = True
-    # set this to true to avoid false error message while creating an instance
-    creating = False
     # set this to true to allow somethings which would'nt be possible
     repairing = False
 
--- a/cwctl.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/cwctl.py	Fri Mar 26 15:53:07 2010 +0100
@@ -383,7 +383,6 @@
         cubes = splitstrip(pop_arg(args, 1))
         appid = pop_arg(args)
         # get the configuration and helper
-        cwcfg.creating = True
         config = cwcfg.config_for(appid, configname)
         config.set_language = False
         cubes = config.expand_cubes(cubes)
@@ -932,8 +931,7 @@
     def i18ninstance_instance(appid):
         """recompile instance's messages catalogs"""
         config = cwcfg.config_for(appid)
-        config.repairing = True # notify this is not a regular start
-        config.read_instance_schema = False # bootstrap schema is enough
+        config.quick_start = True # notify this is not a regular start
         repo = config.repository()
         if config._cubes is None:
             # web only config
--- a/devtools/__init__.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/devtools/__init__.py	Fri Mar 26 15:53:07 2010 +0100
@@ -81,7 +81,6 @@
     mode = 'test'
     set_language = False
     read_instance_schema = False
-    bootstrap_schema = False
     init_repository = True
     options = cwconfig.merge_options(ServerConfiguration.options + (
         ('anonymous-user',
--- a/goa/goaconfig.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/goa/goaconfig.py	Fri Mar 26 15:53:07 2010 +0100
@@ -86,7 +86,7 @@
     cube_appobject_path = WebConfiguration.cube_appobject_path | ServerConfiguration.cube_appobject_path
 
     # use file system schema
-    bootstrap_schema = read_instance_schema = False
+    read_instance_schema = False
     # schema is not persistent, don't load schema hooks (unavailable)
     schema_hooks = False
     # no user workflow for now
--- a/server/__init__.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/server/__init__.py	Fri Mar 26 15:53:07 2010 +0100
@@ -115,11 +115,7 @@
     from cubicweb.server.sqlutils import sqlexec, sqlschema, sqldropschema
     # configuration to avoid db schema loading and user'state checking
     # on connection
-    read_instance_schema = config.read_instance_schema
-    bootstrap_schema = config.bootstrap_schema
-    config.read_instance_schema = False
     config.creating = True
-    config.bootstrap_schema = True
     config.consider_user_state = False
     config.set_language = False
     # only enable the system source at initialization time + admin which is not
@@ -202,8 +198,6 @@
     repo.shutdown()
     # restore initial configuration
     config.creating = False
-    config.read_instance_schema = read_instance_schema
-    config.bootstrap_schema = bootstrap_schema
     config.consider_user_state = True
     config.set_language = True
     print '-> database for instance %s initialized.' % config.appid
--- a/server/migractions.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/server/migractions.py	Fri Mar 26 15:53:07 2010 +0100
@@ -72,7 +72,7 @@
         if config is not None and (cnx or connect):
             self.session.data['rebuild-infered'] = False
             self.repo.hm.call_hooks('server_maintenance', repo=self.repo)
-        if not schema:
+        if not schema and not getattr(config, 'quick_start', False):
             schema = config.load_schema(expand_cubes=True)
         self.fs_schema = schema
         self._synchronized = set()
--- a/server/repository.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/server/repository.py	Fri Mar 26 15:53:07 2010 +0100
@@ -165,7 +165,7 @@
         if config.open_connections_pools:
             self.open_connections_pools()
 
-    def _boostrap_hook_registry(self):
+    def _bootstrap_hook_registry(self):
         """called during bootstrap since we need the metadata hooks"""
         hooksdirectory = join(CW_SOFTWARE_ROOT, 'hooks')
         self.vreg.init_registration([hooksdirectory])
@@ -176,12 +176,15 @@
         config = self.config
         self._available_pools = Queue.Queue()
         self._available_pools.put_nowait(pool.ConnectionsPool(self.sources))
-        if config.read_instance_schema:
-            # normal start: load the instance schema from the database
-            self.fill_schema()
-        elif config.bootstrap_schema:
-            # usually during repository creation
-            self.warning("set fs instance'schema as bootstrap schema")
+        if config.quick_start:
+            # quick start, usually only to get a minimal repository to get cubes
+            # information (eg dump/restore/
+            config._cubes = ()
+            self.set_schema(config.load_schema(), resetvreg=False)
+            config['connections-pool-size'] = 1
+            config._cubes = None
+        elif config.creating:
+            # repository creation
             config.bootstrap_cubes()
             self.set_schema(config.load_schema(), resetvreg=False)
             # need to load the Any and CWUser entity types
@@ -189,8 +192,11 @@
             self.vreg.init_registration([etdirectory])
             for modname in ('__init__', 'authobjs', 'wfobjs'):
                 self.vreg.load_file(join(etdirectory, '%s.py' % modname),
-                                'cubicweb.entities.%s' % modname)
-            self._boostrap_hook_registry()
+                                    'cubicweb.entities.%s' % modname)
+            self._bootstrap_hook_registry()
+        elif config.read_instance_schema:
+            # normal start: load the instance schema from the database
+            self.fill_schema()
         else:
             # test start: use the file system schema (quicker)
             self.warning("set fs instance'schema")
@@ -219,7 +225,10 @@
             self.pools.append(pool.ConnectionsPool(self.sources))
             self._available_pools.put_nowait(self.pools[-1])
         self._shutting_down = False
-        self.hm = self.vreg['hooks']
+        if config.quick_start:
+            config.init_cubes(self.get_cubes())
+        else:
+            self.hm = self.vreg['hooks']
 
     # internals ###############################################################
 
@@ -268,7 +277,8 @@
         self.set_schema(appschema)
 
     def start_looping_tasks(self):
-        if not (self.config.creating or self.config.repairing):
+        if not (self.config.creating or self.config.repairing
+                or self.config.quick_start):
             # call instance level initialisation hooks
             self.hm.call_hooks('server_startup', repo=self)
             # register a task to cleanup expired session
@@ -336,7 +346,8 @@
             self.info('waiting thread %s...', thread.name)
             thread.join()
             self.info('thread %s finished', thread.name)
-        if not (self.config.creating or self.config.repairing):
+        if not (self.config.creating or self.config.repairing
+                or self.config.quick_start):
             self.hm.call_hooks('server_shutdown', repo=self)
         self.close_sessions()
         while not self._available_pools.empty():
@@ -448,6 +459,7 @@
         """
         versions = self.get_versions(not (self.config.creating
                                           or self.config.repairing
+                                          or self.config.quick_start
                                           or self.config.mode == 'test'))
         cubes = list(versions)
         cubes.remove('cubicweb')
--- a/server/serverconfig.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/server/serverconfig.py	Fri Mar 26 15:53:07 2010 +0100
@@ -194,8 +194,11 @@
 
     # read the schema from the database
     read_instance_schema = True
-    bootstrap_schema = True
-
+    # set to true while creating an instance
+    creating = False
+    # set this to true to get a minimal repository, for instance to get cubes
+    # information on commands such as i18ninstance, db-restore, etc...
+    quick_start = False
     # check user's state at login time
     consider_user_state = True
 
--- a/server/serverctl.py	Fri Mar 26 14:13:34 2010 +0100
+++ b/server/serverctl.py	Fri Mar 26 15:53:07 2010 +0100
@@ -389,7 +389,7 @@
             get_connection(
                 system['db-driver'], database=system['db-name'],
                 host=system.get('db-host'), port=system.get('db-port'),
-                user=system.get('db-user'), password=system.get('db-password'), 
+                user=system.get('db-user'), password=system.get('db-password'),
                 **extra)
         except Exception, ex:
             raise ConfigurationError(
@@ -572,20 +572,16 @@
 
 def _local_dump(appid, output):
     config = ServerConfiguration.config_for(appid)
-    config.repairing = True # don't check versions
-    #config.read_instance_schema = False # bootstrap schema is enough
-    # schema=1 to avoid unnecessary fs schema loading
-    mih = config.migration_handler(connect=False, schema=1, verbosity=1)
+    config.quick_start = True
+    mih = config.migration_handler(connect=False, verbosity=1)
     mih.backup_database(output, askconfirm=False)
     mih.shutdown()
 
 def _local_restore(appid, backupfile, drop, systemonly=True):
     config = ServerConfiguration.config_for(appid)
     config.verbosity = 1 # else we won't be asked for confirmation on problems
-    config.repairing = True # don't check versions
-    config.read_instance_schema = False # bootstrap schema is enough
-    # schema=1 to avoid unnecessary fs schema loading
-    mih = config.migration_handler(connect=False, schema=1, verbosity=1)
+    config.quick_start = True
+    mih = config.migration_handler(connect=False, verbosity=1)
     mih.restore_database(backupfile, drop, systemonly, askconfirm=False)
     repo = mih.repo_connect()
     # version of the database