bitbake-layers 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env python3
  2. # This script has subcommands which operate against your bitbake layers, either
  3. # displaying useful information, or acting against them.
  4. # See the help output for details on available commands.
  5. # Copyright (C) 2011 Mentor Graphics Corporation
  6. # Copyright (C) 2011-2015 Intel Corporation
  7. #
  8. # SPDX-License-Identifier: GPL-2.0-only
  9. #
  10. import logging
  11. import os
  12. import sys
  13. import argparse
  14. bindir = os.path.dirname(__file__)
  15. topdir = os.path.dirname(bindir)
  16. sys.path[0:0] = [os.path.join(topdir, 'lib')]
  17. import bb.tinfoil
  18. import bb.msg
  19. logger = bb.msg.logger_create('bitbake-layers', sys.stdout)
  20. def main():
  21. parser = argparse.ArgumentParser(
  22. description="BitBake layers utility",
  23. epilog="Use %(prog)s <subcommand> --help to get help on a specific command",
  24. add_help=False)
  25. parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
  26. parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
  27. parser.add_argument('-F', '--force', help='Force add without recipe parse verification', action='store_true')
  28. parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
  29. global_args, unparsed_args = parser.parse_known_args()
  30. # Help is added here rather than via add_help=True, as we don't want it to
  31. # be handled by parse_known_args()
  32. parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
  33. help='show this help message and exit')
  34. subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
  35. subparsers.required = True
  36. if global_args.debug:
  37. logger.setLevel(logging.DEBUG)
  38. elif global_args.quiet:
  39. logger.setLevel(logging.ERROR)
  40. # Need to re-run logger_create with color argument
  41. # (will be the same logger since it has the same name)
  42. bb.msg.logger_create('bitbake-layers', output=sys.stdout,
  43. color=global_args.color,
  44. level=logger.getEffectiveLevel())
  45. plugins = []
  46. tinfoil = bb.tinfoil.Tinfoil(tracking=True)
  47. tinfoil.logger.setLevel(logger.getEffectiveLevel())
  48. try:
  49. tinfoil.prepare(True)
  50. for path in ([topdir] +
  51. tinfoil.config_data.getVar('BBPATH').split(':')):
  52. pluginpath = os.path.join(path, 'lib', 'bblayers')
  53. bb.utils.load_plugins(logger, plugins, pluginpath)
  54. registered = False
  55. for plugin in plugins:
  56. if hasattr(plugin, 'register_commands'):
  57. registered = True
  58. plugin.register_commands(subparsers)
  59. if hasattr(plugin, 'tinfoil_init'):
  60. plugin.tinfoil_init(tinfoil)
  61. if not registered:
  62. logger.error("No commands registered - missing plugins?")
  63. sys.exit(1)
  64. args = parser.parse_args(unparsed_args, namespace=global_args)
  65. if getattr(args, 'parserecipes', False):
  66. tinfoil.config_data.disableTracking()
  67. tinfoil.parse_recipes()
  68. tinfoil.config_data.enableTracking()
  69. return args.func(args)
  70. finally:
  71. tinfoil.shutdown()
  72. if __name__ == "__main__":
  73. try:
  74. ret = main()
  75. except bb.BBHandledException:
  76. ret = 1
  77. except Exception:
  78. ret = 1
  79. import traceback
  80. traceback.print_exc()
  81. sys.exit(ret)