瀏覽代碼

Begin implementation of new plugin list retrieval

Yann Weber 8 年之前
父節點
當前提交
6a18cf7fa2
共有 4 個檔案被更改,包括 45 行新增1 行删除
  1. 12
    0
      lodel/plugin/datasource_plugin.py
  2. 15
    0
      lodel/plugin/plugins.py
  3. 1
    1
      lodel/settings/settings.py
  4. 17
    0
      lodel/settings/validator.py

+ 12
- 0
lodel/plugin/datasource_plugin.py 查看文件

@@ -1,5 +1,6 @@
1 1
 from .plugins import Plugin
2 2
 from .exceptions import *
3
+from lodel.settings.validator import SettingValidator
3 4
 
4 5
 ##@brief Designed to handles datasources plugins
5 6
 #
@@ -10,6 +11,13 @@ from .exceptions import *
10 11
 #@todo Refactor and rewrite lodel2 datasource handling
11 12
 class DatasourcePlugin(Plugin):
12 13
     
14
+    ##@brief Stores confspecs indicating where DatasourcePlugin list is stored
15
+    _plist_confspecs = {
16
+        'section': 'lodel2',
17
+        'key': 'datasources',
18
+        'default': None,
19
+        'validator': SettingValidator('list', none_is_valid = False) }
20
+    
13 21
     def __init__(self, name):
14 22
         super().__init__(name)
15 23
         self.__datasource_cls = None
@@ -22,6 +30,10 @@ class DatasourcePlugin(Plugin):
22 30
     def migration_handler(self):
23 31
         return self.loader_module().migration_handler_class()
24 32
 
33
+    @classmethod
34
+    def plist_confspec(cls):
35
+        return copy.copy(cls._plist_confspecs)
36
+
25 37
     ##@brief Return an initialized Datasource instance
26 38
     #@param ds_name str : The name of the datasource to instanciate
27 39
     #@param ro bool

+ 15
- 0
lodel/plugin/plugins.py 查看文件

@@ -430,6 +430,21 @@ name differ from the one found in plugin's init file"
430 430
     def confspecs(self):
431 431
         return copy.copy(self.__confspecs)
432 432
 
433
+    ##@brief Retrieves plugin list confspecs
434
+    #
435
+    #This method ask for each Plugin child class the confspecs specifying where
436
+    #the wanted plugin list is stored. (For example DatasourcePlugin expect
437
+    #that a list of ds plugin to load stored in lodel2 section, datasources key
438
+    # etc...
439
+    @classmethod
440
+    def plugin_list_confspec(cls):
441
+        from lodel.settings.validator import confspec_append
442
+        res = dict()
443
+        for pcls in cls.plugin_types():
444
+            plcs = pcls.plist_confspec()
445
+            confspec_append(res, plcs)
446
+        return res
447
+
433 448
     ##@brief Attempt to read plugin discover cache
434 449
     #@note If no cache yet make a discover with default plugin directory
435 450
     #@return a dict (see @ref _discover() )

+ 1
- 1
lodel/settings/settings.py 查看文件

@@ -128,7 +128,7 @@ class Settings(object, metaclass=MetaSettings):
128 128
         confkey=confname.rpartition('.')
129 129
         loader.setoption(confkey[0], confkey[2], confvalue, validator)
130 130
 
131
-    ##@brief This method handlers Settings instance bootstraping
131
+    ##@brief This method handles Settings instance bootstraping
132 132
     def __bootstrap(self):
133 133
         logger.debug("Settings bootstraping")
134 134
         lodel2_specs = LODEL2_CONF_SPECS

+ 17
- 0
lodel/settings/validator.py 查看文件

@@ -352,6 +352,23 @@ SettingValidator.create_re_validator(
352 352
 #   Lodel 2 configuration specification
353 353
 #
354 354
 
355
+##@brief Append a piece of confspec
356
+#@note orig is modified during the process
357
+#@param orig dict : the confspec to update
358
+#@param upd dict : the confspec to add
359
+#@return new confspec
360
+def confspec_append(orig, upd):
361
+    for section in orig:
362
+        if section in upd:
363
+            orig[section].update(upd[section])
364
+        else:
365
+            orig[section] = upd[section]
366
+    return orig
367
+
368
+def confspec_add(orig, section, key, default, validator):
369
+    if section not in orig:
370
+        section[orig] = dict()
371
+
355 372
 ##@brief Global specifications for lodel2 settings
356 373
 LODEL2_CONF_SPECS = {
357 374
     'lodel2': {

Loading…
取消
儲存