No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

core_hooks.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #-*- coding: utf-8 -*-
  2. from lodel.plugin import LodelHook
  3. from lodel.settings import Settings
  4. from lodel import logger
  5. ##@package lodel.plugin.core_hooks
  6. #@brief Lodel2 internal hooks declaration
  7. ##@brief Bootstrap hook to check datasources configuration
  8. @LodelHook('lodel2_bootstraped')
  9. def datasources_bootstrap_hook(hook_name, caller, payload):
  10. for ds_name in Settings.datasources._fields:
  11. ds_conf = getattr(Settings.datasources, ds_name)
  12. identifier = getattr(ds_conf, 'identifier')
  13. # Now we are trying to fetch the datasource given the identifier
  14. ds_family_name, ds_name = identifier.split('.',1)
  15. try:
  16. ds_fam = getattr(Settings.datasource, ds_family_name)
  17. except AttributeError:
  18. msg = "No datasource family named '%s' found"
  19. msg %= ds_family_name
  20. raise NameError(msg)
  21. try:
  22. ds = getattr(ds_fam, ds_name)
  23. except AttributeError:
  24. msg = "No datasource configured for identifier '%s' found"
  25. msg %= identifier
  26. raise NameError(msg)
  27. log_msg = "Found a datasource named '%s' identified by '%s'"
  28. log_msg %= (ds_name, identifier)
  29. logger.debug(log_msg)
  30. ##@brief Bootstrap hook that print debug infos about registered hooks
  31. @LodelHook('lodel2_bootstraped')
  32. def list_hook_debug_hook(name, caller, payload):
  33. from lodel import logger
  34. hlist = LodelHook.hook_list()
  35. for name, reg_hooks in hlist.items():
  36. for hook, priority in reg_hooks:
  37. logger.debug("{modname}.{funname} is registered as hook \
  38. {hookname} with priority {priority}".format(
  39. modname = hook.__module__,
  40. funname = hook.__name__,
  41. priority = priority,
  42. hookname = name))
  43. ##@brief Hooks that trigger custom methods injection in dynmic classes
  44. @LodelHook("lodel2_dyncode_loaded")
  45. def lodel2_plugins_custom_methods(self, caller, dynclasses):
  46. from lodel.plugin.plugins import CustomMethod
  47. CustomMethod.set_registered(dynclasses)