Переглянути джерело

Modifying settings class to allow usage of custom confspecs

a bit dirty & quick
Yann Weber 7 роки тому
джерело
коміт
0ffe60ff2b
1 змінених файлів з 9 додано та 3 видалено
  1. 9
    3
      lodel/settings/settings.py

+ 9
- 3
lodel/settings/settings.py Переглянути файл

@@ -80,13 +80,15 @@ class Settings(object, metaclass=MetaSettings):
80 80
     
81 81
     ## @brief Instanciate the Settings singleton
82 82
     # @param conf_dir str : The configuration directory
83
-    def __init__(self, conf_dir):
83
+    #@param custom_confspec None | dict : if given overwrite default lodel2
84
+    #confspecs
85
+    def __init__(self, conf_dir, custom_confspecs = None):
84 86
         self.singleton_assert() # check that it is the only instance
85 87
         Settings.instance = self
86 88
         ## @brief Configuration specification
87 89
         #
88 90
         # Initialized by Settings.__bootstrap() method
89
-        self.__conf_specs = None
91
+        self.__conf_specs = custom_confspecs
90 92
         ## @brief Stores the configurations in namedtuple tree
91 93
         self.__confs = None
92 94
         self.__conf_dir = conf_dir
@@ -137,7 +139,11 @@ class Settings(object, metaclass=MetaSettings):
137 139
         LodelContext.expose_modules(globals(), {
138 140
             'lodel.plugin.plugins': ['Plugin', 'PluginError']})
139 141
         logger.debug("Settings bootstraping")
140
-        lodel2_specs = LODEL2_CONF_SPECS
142
+        if self.__conf_specs is None:
143
+            lodel2_specs = LODEL2_CONF_SPECS
144
+        else:
145
+            lodel2_specs = self.__conf_specs
146
+            self.__conf_specs = None
141 147
         loader = SettingsLoader(self.__conf_dir) 
142 148
         plugin_list = []
143 149
         for ptype_name,ptype in Plugin.plugin_types().items():

Loading…
Відмінити
Зберегти