1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-04-17 14:39:58 +02:00
lodel2_mirror/lodel/plugin/core_hooks.py
Yann 83afc6b6dd Deleted datasources plugins and add a settings for datasources declaration
- now datasources are declared with two conf keys : read_only and identifier
- the old datasources plugin hook is now declared in lodel/plugin/core_hooks.py. This file is imported after lodel/plugin/hooks.py in the loader.py
2016-06-09 14:35:31 +02:00

35 lines
1.2 KiB
Python

#-*- coding: utf-8 -*-
from lodel.plugin import LodelHook
from lodel.settings import Settings
from lodel import logger
##@package lodel.plugin.core_hooks
#@brief Lodel2 internal hooks declaration
##@brief Bootstrap hook to check datasources configuration
@LodelHook('lodel2_bootstraped')
def datasources_bootstrap_callaback(hook_name, caller, payload):
for ds_name in Settings.datasources._fields:
ds_conf = getattr(Settings.datasources, ds_name)
identifier = getattr(ds_conf, 'identifier')
# Now we are trying to fetch the datasource given the identifier
ds_family_name, ds_name = identifier.split('.',1)
try:
ds_fam = getattr(Settings.datasource, ds_family_name)
except AttributeError:
msg = "No datasource family named '%s' found"
msg %= ds_family_name
raise NameError(msg)
try:
ds = getattr(ds_fam, ds_name)
except AttributeError:
msg = "No datasource configured for identifier '%s' found"
msg %= identifier
raise NameError(msg)
log_msg = "Found a datasource named '%s' identified by '%s'"
log_msg %= (ds_name, identifier)
logger.debug(log_msg)