bbpath.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import argparse
  2. already_loaded = False
  3. kept_context = None
  4. def plugin_name(filename):
  5. return os.path.splitext(os.path.basename(filename))[0]
  6. def plugin_init(plugins):
  7. global already_loaded
  8. already_loaded = plugin_name(__file__) in (plugin_name(p.__name__) for p in plugins)
  9. def print_name(args, config, basepath, workspace):
  10. print (__file__)
  11. def print_bbdir(args, config, basepath, workspace):
  12. print (__file__.replace('/lib/devtool/bbpath.py',''))
  13. def print_registered(args, config, basepath, workspace):
  14. global kept_context
  15. print(kept_context.loaded)
  16. def multiloaded(args, config, basepath, workspace):
  17. global already_loaded
  18. print("yes" if already_loaded else "no")
  19. def register_commands(subparsers, context):
  20. global kept_context
  21. kept_context = context
  22. if 'loaded' in context.__dict__:
  23. context.loaded += 1
  24. else:
  25. context.loaded = 1
  26. def addparser(name, helptxt, func):
  27. parser = subparsers.add_parser(name, help=helptxt,
  28. formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  29. parser.set_defaults(func=func)
  30. return parser
  31. addparser('pluginfile', 'Print the filename of this plugin', print_name)
  32. addparser('bbdir', 'Print the BBPATH directory of this plugin', print_bbdir)
  33. addparser('count', 'How many times have this plugin been registered.', print_registered)
  34. addparser('multiloaded', 'How many times have this plugin been initialized', multiloaded)