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