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.2KB

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