[config] generalise config.creating, allowing to drop set_language class attribute stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 28 Mar 2011 18:56:55 +0200
branchstable
changeset 7129 455b503fb7ff
parent 7128 f1fe05d5224e
child 7130 5eb622c0c672
[config] generalise config.creating, allowing to drop set_language class attribute
cwconfig.py
cwctl.py
devtools/__init__.py
server/__init__.py
server/serverconfig.py
--- a/cwconfig.py	Mon Mar 28 18:53:54 2011 +0200
+++ b/cwconfig.py	Mon Mar 28 18:56:55 2011 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -843,9 +843,8 @@
         if not exists(_INSTANCES_DIR):
             os.makedirs(_INSTANCES_DIR)
 
-    # for some commands (creation...) we don't want to initialize gettext
-    set_language = True
-    # set this to true to allow somethings which would'nt be possible
+    # set to true during repair (shell, migration) to allow some things which
+    # wouldn't be possible otherwise
     repairing = False
 
     options = CubicWebNoAppConfiguration.options + (
@@ -900,13 +899,13 @@
         return mdir
 
     @classmethod
-    def config_for(cls, appid, config=None, debugmode=False):
+    def config_for(cls, appid, config=None, debugmode=False, creating=False):
         """return a configuration instance for the given instance identifier
         """
         cls.load_available_configs()
         config = config or guess_configuration(cls.instance_home(appid))
         configcls = configuration_cls(config)
-        return configcls(appid, debugmode)
+        return configcls(appid, debugmode, creating)
 
     @classmethod
     def possible_configurations(cls, appid):
@@ -966,8 +965,6 @@
             log_path = os.path.join(_INSTALL_PREFIX, 'var', 'log', 'cubicweb', '%s-%s.log')
             return log_path % (self.appid, self.name)
 
-
-
     def default_pid_file(self):
         """return default path to the pid file of the instance'server"""
         if self.mode == 'system':
@@ -985,8 +982,10 @@
 
     # instance methods used to get instance specific resources #############
 
-    def __init__(self, appid, debugmode=False):
+    def __init__(self, appid, debugmode=False, creating=False):
         self.appid = appid
+        # set to true while creating an instance
+        self.creating = creating
         super(CubicWebConfiguration, self).__init__(debugmode)
         fake_gettext = (unicode, lambda ctx, msgid: unicode(msgid))
         for lang in self.available_languages():
@@ -1077,7 +1076,7 @@
     def load_configuration(self):
         """load instance's configuration files"""
         super(CubicWebConfiguration, self).load_configuration()
-        if self.apphome and self.set_language:
+        if self.apphome and not self.creating:
             # init gettext
             self._gettext_init()
 
--- a/cwctl.py	Mon Mar 28 18:53:54 2011 +0200
+++ b/cwctl.py	Mon Mar 28 18:56:55 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -343,8 +343,7 @@
         cubes, appid = args
         cubes = splitstrip(cubes)
         # get the configuration and helper
-        config = cwcfg.config_for(appid, configname)
-        config.set_language = False
+        config = cwcfg.config_for(appid, configname, creating=True)
         cubes = config.expand_cubes(cubes)
         config.init_cubes(cubes)
         helper = self.config_helper(config)
--- a/devtools/__init__.py	Mon Mar 28 18:53:54 2011 +0200
+++ b/devtools/__init__.py	Mon Mar 28 18:56:55 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -127,7 +127,6 @@
 
 class TestServerConfiguration(ServerConfiguration):
     mode = 'test'
-    set_language = False
     read_instance_schema = False
     init_repository = True
 
--- a/server/__init__.py	Mon Mar 28 18:53:54 2011 +0200
+++ b/server/__init__.py	Mon Mar 28 18:56:55 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -129,7 +129,6 @@
     # on connection
     config.creating = True
     config.consider_user_state = False
-    config.set_language = False
     # only enable the system source at initialization time
     repo = Repository(config, vreg=vreg)
     schema = repo.schema
@@ -210,7 +209,6 @@
     # restore initial configuration
     config.creating = False
     config.consider_user_state = True
-    config.set_language = True
     print '-> database for instance %s initialized.' % config.appid
 
 
--- a/server/serverconfig.py	Mon Mar 28 18:53:54 2011 +0200
+++ b/server/serverconfig.py	Mon Mar 28 18:56:55 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -215,8 +215,6 @@
 
     # read the schema from the database
     read_instance_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