Ingen beskrivning
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_scripts.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from lodel.context import LodelContext
  2. LodelContext.expose_modules(globals(), {
  3. 'lodel.plugin.scripts': 'lodel_script'})
  4. ##@package lodel.plugin.core_scripts
  5. #@brief Lodel2 internal scripts declaration
  6. #@ingroup lodel2_plugins
  7. #@ingroup lodel2_script
  8. ##@brief Implements lodel_admin.py **discover-plugin** action
  9. #@ingroup lodel2_plugins
  10. #@ingroup lodel2_script
  11. #
  12. #In depth directory scan to find plugins in order to build a plugin list.
  13. class DiscoverPlugin(lodel_script.LodelScript):
  14. _action = 'discover-plugin'
  15. _description = 'Walk through given folders looking for plugins'
  16. @classmethod
  17. def argparser_config(cls, parser):
  18. #parser.add_argument('-d', '--directory',
  19. parser.add_argument('PLUGIN_PATH',
  20. help="Directory to walk through looking for lodel2 plugins",
  21. nargs='+')
  22. parser.add_argument('-l', '--list-only', default=False,
  23. action = 'store_true',
  24. help="Use this option to print a list of discovered plugins \
  25. without modifying existing cache")
  26. @classmethod
  27. def run(cls, args):
  28. from lodel.plugin.plugins import Plugin
  29. if args.PLUGIN_PATH is None or len(args.PLUGIN_PATH) == 0:
  30. cls.help_exit("Specify a least one directory")
  31. no_cache = args.list_only
  32. res = Plugin.discover(args.PLUGIN_PATH, no_cache)
  33. print("Found plugins in : %s" % ', '.join(args.PLUGIN_PATH))
  34. for pname, pinfos in res['plugins'].items():
  35. print("\t- %s(%s) in %s" % (
  36. pname, pinfos['version'], pinfos['path']))
  37. ##@brief Implements lodel_admin.py **hooks-list** action
  38. #@ingroup lodel2_script
  39. #@ingroup lodel2_hooks
  40. class ListHooks(lodel_script.LodelScript):
  41. _action = 'hooks-list'
  42. _description = 'Generate a list of registered hooks once instance started'
  43. @classmethod
  44. def argparser_config(cls, parser):
  45. pass
  46. @classmethod
  47. def run(cls, args):
  48. import loader
  49. loader.start()
  50. from lodel.plugin.hooks import LodelHook
  51. hlist = LodelHook.hook_list()
  52. print("Registered hooks : ")
  53. for name in sorted(hlist.keys()):
  54. print("\t- %s is registered by :" % name)
  55. for hfun, priority in hlist[name]:
  56. msg = "\t\t- {modname}.{funname} with priority : {priority}"
  57. print(msg.format(
  58. modname = hfun.__module__,
  59. funname = hfun.__name__,
  60. priority = priority))
  61. print("\n")