[OE-core] [PATCHv2 3/6] recipetool: also load plugins from BBPATH

Paul Eggleton paul.eggleton at linux.intel.com
Wed Jul 22 10:55:10 UTC 2015


Hi Chris,

On Monday 20 July 2015 15:15:53 Christopher Larson wrote:
> This makes it easier to extend, as a layer can add its own sub-commands.
> 
> [YOCTO #7625]
> 
> Signed-off-by: Christopher Larson <kergoth at gmail.com>
> Signed-off-by: Ross Burton <ross.burton at intel.com>
> ---
>  scripts/recipetool | 52
> ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32
> insertions(+), 20 deletions(-)
> 
> diff --git a/scripts/recipetool b/scripts/recipetool
> index 3063cf7..6061d7b 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():
> 
> @@ -49,28 +46,22 @@ def main():
>          sys.exit(1)
> 
>      parser = argparse.ArgumentParser(description="OpenEmbedded recipe
> tool", +                                     add_help=False,
>                                       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>') -
> -    scriptutils.load_plugins(logger, plugins, os.path.join(scripts_path,
> 'lib', 'recipetool')) -    registered = False
> -    for plugin in plugins:
> -        if hasattr(plugin, 'register_command'):
> -            registered = True
> -            plugin.register_command(subparsers)
> 
> -    if not registered:
> -        logger.error("No commands registered - missing plugins?")
> -        sys.exit(1)
> +    initial_args, unparsed_args = parser.parse_known_args(sys.argv[1:])
> 
> -    args = parser.parse_args()
> +    # Help is added here rather than via add_help=True, as we don't want it
> to +    # be handled by parse_known_args()
> +    parser.add_argument('-h', '--help', action='help',
> default=argparse.SUPPRESS, +                        help='show this help
> message and exit')
> 
> -    if args.debug:
> +    if initial_args.debug:
>          logger.setLevel(logging.DEBUG)
> -    elif args.quiet:
> +    elif initial_args.quiet:
>          logger.setLevel(logging.ERROR)
> 
>      import scriptpath
> @@ -80,10 +71,31 @@ def main():
>          sys.exit(1)
>      logger.debug('Found bitbake path: %s' % bitbakepath)
> 
> -    scriptutils.logger_setup_color(logger, args.color)
> +    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(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

I must admit it wasn't immediately obvious to me why you'd made some of the 
changes here, although after several reads it does make sense - would you be 
able to add a slightly more detailed commit message explaining the changes? 
(same for the equivalent devtool patch).

Thanks,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre



More information about the Openembedded-core mailing list