[OE-core] [PATCH 2/3] recipetool: also load plugins from BBPATH
Christopher Larson
kergoth at gmail.com
Mon Jun 29 20:50:06 UTC 2015
This makes it easier to extend, as a layer can add its own sub-commands.
Signed-off-by: Christopher Larson <kergoth at gmail.com>
---
scripts/recipetool | 67 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 40 insertions(+), 27 deletions(-)
diff --git a/scripts/recipetool b/scripts/recipetool
index 3063cf7..5ebef6b 100755
--- a/scripts/recipetool
+++ b/scripts/recipetool
@@ -36,11 +36,8 @@ def tinfoil_init(parserecipes):
import logging
tinfoil = bb.tinfoil.Tinfoil()
tinfoil.prepare(not parserecipes)
-
- for plugin in plugins:
- if hasattr(plugin, 'tinfoil_init'):
- plugin.tinfoil_init(tinfoil)
tinfoil.logger.setLevel(logger.getEffectiveLevel())
+ return tinfoil
def main():
@@ -48,42 +45,58 @@ def main():
logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
sys.exit(1)
- parser = argparse.ArgumentParser(description="OpenEmbedded recipe tool",
- epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
- parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
- parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
- parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
- subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
+ def create_global_parser(**kwargs):
+ parser = argparse.ArgumentParser(description="OpenEmbedded recipe tool",
+ epilog="Use %(prog)s <subcommand> --help to get help on a specific command", **kwargs)
+ parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
+ parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
+ parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
+ return parser
+
+ parser = create_global_parser(add_help=False)
+ initial_args, unparsed_args = parser.parse_known_args(sys.argv[1:])
+ if initial_args.debug:
+ logger.setLevel(logging.DEBUG)
+ elif initial_args.quiet:
+ logger.setLevel(logging.ERROR)
+
+ # Re-create the parser here because adding the subparsers doesn't cause
+ # ArgumentParser to re-generate the formatted help text after
+ # parse_known_args()
+ parser = create_global_parser()
+
+ import scriptpath
+ bitbakepath = scriptpath.add_bitbake_lib_path()
+ if not bitbakepath:
+ logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
+ sys.exit(1)
+ logger.debug('Found bitbake path: %s' % bitbakepath)
- scriptutils.load_plugins(logger, plugins, os.path.join(scripts_path, 'lib', 'recipetool'))
+ scriptutils.logger_setup_color(logger, initial_args.color)
+
+ subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
+ tinfoil = tinfoil_init(False)
+ for path in ([scripts_path] +
+ tinfoil.config_data.getVar('BBPATH', True).split(':')):
+ pluginpath = os.path.join(path, 'lib', 'recipetool')
+ scriptutils.load_plugins(logger, plugins, pluginpath)
registered = False
for plugin in plugins:
if hasattr(plugin, 'register_command'):
registered = True
plugin.register_command(subparsers)
+ if hasattr(plugin, 'tinfoil_init'):
+ plugin.tinfoil_init(tinfoil)
if not registered:
logger.error("No commands registered - missing plugins?")
sys.exit(1)
- args = parser.parse_args()
-
- if args.debug:
- logger.setLevel(logging.DEBUG)
- elif args.quiet:
- logger.setLevel(logging.ERROR)
-
- import scriptpath
- bitbakepath = scriptpath.add_bitbake_lib_path()
- if not bitbakepath:
- logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
- sys.exit(1)
- logger.debug('Found bitbake path: %s' % bitbakepath)
-
- scriptutils.logger_setup_color(logger, args.color)
+ args = parser.parse_args(unparsed_args, namespace=initial_args)
try:
- tinfoil_init(getattr(args, 'parserecipes', False))
+ if getattr(args, 'parserecipes', False):
+ tinfoil.parseRecipes()
ret = args.func(args)
except bb.BBHandledException:
ret = 1
--
2.2.1
More information about the Openembedded-core
mailing list