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,6 +157,8 @@ to generic PluginVersion comparison function : '%s'" % cmp_fun_name)
157 157
 # 1. Settings call start method to instanciate all plugins found in confs
158 158
 # 2. Settings fetch all confspecs
159 159
 # 3. the loader call load_all to register hooks etc
160
+#
161
+#@todo add log messages (now we can)
160 162
 class Plugin(object):
161 163
     
162 164
     ##@brief Stores plugin directories paths
@@ -438,6 +440,7 @@ name differ from the one found in plugin's init file"
438 440
             raise PluginError(msg)
439 441
         plugin = cls(plugin_name)
440 442
         cls._plugin_instances[plugin_name] = plugin
443
+        logger.debug("Plugin %s available." % plugin)
441 444
         return plugin
442 445
 
443 446
     ##@brief Plugins instances accessor

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

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

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

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

Loading…
Cancel
Save