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_scripts.py 2.4KB

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