1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-03-14 15:22:02 +01:00

Begin implementation of new plugin list retrieval

This commit is contained in:
Yann 2016-08-19 14:19:35 +02:00
commit 6a18cf7fa2
4 changed files with 45 additions and 1 deletions

View file

@ -1,5 +1,6 @@
from .plugins import Plugin
from .exceptions import *
from lodel.settings.validator import SettingValidator
##@brief Designed to handles datasources plugins
#
@ -10,6 +11,13 @@ from .exceptions import *
#@todo Refactor and rewrite lodel2 datasource handling
class DatasourcePlugin(Plugin):
##@brief Stores confspecs indicating where DatasourcePlugin list is stored
_plist_confspecs = {
'section': 'lodel2',
'key': 'datasources',
'default': None,
'validator': SettingValidator('list', none_is_valid = False) }
def __init__(self, name):
super().__init__(name)
self.__datasource_cls = None
@ -22,6 +30,10 @@ class DatasourcePlugin(Plugin):
def migration_handler(self):
return self.loader_module().migration_handler_class()
@classmethod
def plist_confspec(cls):
return copy.copy(cls._plist_confspecs)
##@brief Return an initialized Datasource instance
#@param ds_name str : The name of the datasource to instanciate
#@param ro bool

View file

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

View file

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

View file

@ -352,6 +352,23 @@ SettingValidator.create_re_validator(
# Lodel 2 configuration specification
#
##@brief Append a piece of confspec
#@note orig is modified during the process
#@param orig dict : the confspec to update
#@param upd dict : the confspec to add
#@return new confspec
def confspec_append(orig, upd):
for section in orig:
if section in upd:
orig[section].update(upd[section])
else:
orig[section] = upd[section]
return orig
def confspec_add(orig, section, key, default, validator):
if section not in orig:
section[orig] = dict()
##@brief Global specifications for lodel2 settings
LODEL2_CONF_SPECS = {
'lodel2': {