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