Browse Source

Settings started detection mechanism enhancement + early log message creation (for plugins & settings)

Yann Weber 8 years ago
parent
commit
16ef4d9d3f
3 changed files with 15 additions and 2 deletions
  1. 3
    0
      lodel/plugin/plugins.py
  2. 6
    1
      lodel/settings/settings.py
  3. 6
    1
      lodel/settings/settings_loader.py

+ 3
- 0
lodel/plugin/plugins.py View File

157
 # 1. Settings call start method to instanciate all plugins found in confs
157
 # 1. Settings call start method to instanciate all plugins found in confs
158
 # 2. Settings fetch all confspecs
158
 # 2. Settings fetch all confspecs
159
 # 3. the loader call load_all to register hooks etc
159
 # 3. the loader call load_all to register hooks etc
160
+#
161
+#@todo add log messages (now we can)
160
 class Plugin(object):
162
 class Plugin(object):
161
     
163
     
162
     ##@brief Stores plugin directories paths
164
     ##@brief Stores plugin directories paths
438
             raise PluginError(msg)
440
             raise PluginError(msg)
439
         plugin = cls(plugin_name)
441
         plugin = cls(plugin_name)
440
         cls._plugin_instances[plugin_name] = plugin
442
         cls._plugin_instances[plugin_name] = plugin
443
+        logger.debug("Plugin %s available." % plugin)
441
         return plugin
444
         return plugin
442
 
445
 
443
     ##@brief Plugins instances accessor
446
     ##@brief Plugins instances accessor

+ 6
- 1
lodel/settings/settings.py View File

68
 # '.*')
68
 # '.*')
69
 # @todo delete the first stage, the lib path HAVE TO BE HARDCODED. In fact
69
 # @todo delete the first stage, the lib path HAVE TO BE HARDCODED. In fact
70
 #when we will run lodel in production the lodel2 lib will be in the python path
70
 #when we will run lodel in production the lodel2 lib will be in the python path
71
+#@todo add log messages (now we can)
71
 class Settings(object, metaclass=MetaSettings):
72
 class Settings(object, metaclass=MetaSettings):
72
 
73
 
73
     ## @brief Stores the singleton instance
74
     ## @brief Stores the singleton instance
85
         ## @brief Stores the configurations in namedtuple tree
86
         ## @brief Stores the configurations in namedtuple tree
86
         self.__confs = None
87
         self.__confs = None
87
         self.__conf_dir = conf_dir
88
         self.__conf_dir = conf_dir
89
+        self.__started = False
88
         self.__bootstrap()
90
         self.__bootstrap()
89
     
91
     
90
     ## @brief Get the named tuple representing configuration
92
     ## @brief Get the named tuple representing configuration
100
 
102
 
101
     @classmethod
103
     @classmethod
102
     def started(cls):
104
     def started(cls):
103
-        return cls.instance is not None and cls.instance.__confs is not None
105
+        return cls.instance is not None and cls.instance.__started
104
 
106
 
105
     ##@brief An utility method that raises if the singleton is not in a good
107
     ##@brief An utility method that raises if the singleton is not in a good
106
     # state
108
     # state
128
 
130
 
129
     ##@brief This method handlers Settings instance bootstraping
131
     ##@brief This method handlers Settings instance bootstraping
130
     def __bootstrap(self):
132
     def __bootstrap(self):
133
+        logger.debug("Settings bootstraping")
131
         lodel2_specs = LODEL2_CONF_SPECS
134
         lodel2_specs = LODEL2_CONF_SPECS
132
         for section in lodel2_specs:
135
         for section in lodel2_specs:
133
             if section.lower() != section:
136
             if section.lower() != section:
154
                                             plugins_path_opt_specs[0],
157
                                             plugins_path_opt_specs[0],
155
                                             False)
158
                                             False)
156
         # Starting the Plugins class
159
         # Starting the Plugins class
160
+        logger.debug("Starting lodel.plugin.Plugin class")
157
         Plugin.start(plugins_path, plugins_list)
161
         Plugin.start(plugins_path, plugins_list)
158
         # Fetching conf specs from plugins
162
         # Fetching conf specs from plugins
159
         specs = [lodel2_specs]
163
         specs = [lodel2_specs]
167
             raise SettingsErrors(errors)
171
             raise SettingsErrors(errors)
168
         self.__conf_specs = self.__merge_specs(specs)
172
         self.__conf_specs = self.__merge_specs(specs)
169
         self.__populate_from_specs(self.__conf_specs, loader)
173
         self.__populate_from_specs(self.__conf_specs, loader)
174
+        self.__started = True
170
     
175
     
171
     ##@brief Produce a configuration specification dict by merging all specifications
176
     ##@brief Produce a configuration specification dict by merging all specifications
172
     #
177
     #

+ 6
- 1
lodel/settings/settings_loader.py View File

4
 import glob
4
 import glob
5
 import copy
5
 import copy
6
 
6
 
7
+from lodel import logger
7
 from lodel.settings.utils import *
8
 from lodel.settings.utils import *
8
 from lodel.settings.validator import SettingsValidationError
9
 from lodel.settings.validator import SettingsValidationError
9
 from lodel.settings.utils import SettingsError, SettingsErrors
10
 from lodel.settings.utils import SettingsError, SettingsErrors
32
     # @return dict()
33
     # @return dict()
33
     def __merge(self):
34
     def __merge(self):
34
         conf = dict()
35
         conf = dict()
35
-        l_dir = glob.glob(self.__conf_path+'/*.ini')  
36
+        l_dir = glob.glob(self.__conf_path+'/*.ini')
37
+        logger.debug("SettingsLoader found those settings files : %s" % (
38
+            ', '.join(l_dir)))
36
 
39
 
37
         for f_ini in l_dir:  
40
         for f_ini in l_dir:  
38
             config = configparser.ConfigParser(default_section = self.DEFAULT_SECTION ,interpolation=None)
41
             config = configparser.ConfigParser(default_section = self.DEFAULT_SECTION ,interpolation=None)
86
             sec[keyname]['value'] = default_value
89
             sec[keyname]['value'] = default_value
87
             sec[keyname]['file'] = SettingsLoader.DEFAULT_FILENAME
90
             sec[keyname]['file'] = SettingsLoader.DEFAULT_FILENAME
88
             result = default_value
91
             result = default_value
92
+            logger.debug("Using default value for configuration key %s:%s" % (
93
+                section, keyname))
89
 
94
 
90
         try:
95
         try:
91
             return validator(result)
96
             return validator(result)

Loading…
Cancel
Save