bitbake-layers 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License version 2 as
  12. # published by the Free Software Foundation.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. import logging
  23. import os
  24. import sys
  25. import argparse
  26. import signal
  27. bindir = os.path.dirname(__file__)
  28. topdir = os.path.dirname(bindir)
  29. sys.path[0:0] = [os.path.join(topdir, 'lib')]
  30. import bb.tinfoil
  31. import bb.msg
  32. logger = bb.msg.logger_create('bitbake-layers', sys.stdout)
  33. def main():
  34. signal.signal(signal.SIGPIPE, signal.SIG_DFL)
  35. parser = argparse.ArgumentParser(
  36. description="BitBake layers utility",
  37. epilog="Use %(prog)s <subcommand> --help to get help on a specific command",
  38. add_help=False)
  39. parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
  40. parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
  41. parser.add_argument('-F', '--force', help='Force add without recipe parse verification', action='store_true')
  42. parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
  43. global_args, unparsed_args = parser.parse_known_args()
  44. # Help is added here rather than via add_help=True, as we don't want it to
  45. # be handled by parse_known_args()
  46. parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
  47. help='show this help message and exit')
  48. subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
  49. subparsers.required = True
  50. if global_args.debug:
  51. logger.setLevel(logging.DEBUG)
  52. elif global_args.quiet:
  53. logger.setLevel(logging.ERROR)
  54. # Need to re-run logger_create with color argument
  55. # (will be the same logger since it has the same name)
  56. bb.msg.logger_create('bitbake-layers', output=sys.stdout, color=global_args.color)
  57. plugins = []
  58. tinfoil = bb.tinfoil.Tinfoil(tracking=True)
  59. tinfoil.logger.setLevel(logger.getEffectiveLevel())
  60. try:
  61. tinfoil.prepare(True)
  62. for path in ([topdir] +
  63. tinfoil.config_data.getVar('BBPATH').split(':')):
  64. pluginpath = os.path.join(path, 'lib', 'bblayers')
  65. bb.utils.load_plugins(logger, plugins, pluginpath)
  66. registered = False
  67. for plugin in plugins:
  68. if hasattr(plugin, 'register_commands'):
  69. registered = True
  70. plugin.register_commands(subparsers)
  71. if hasattr(plugin, 'tinfoil_init'):
  72. plugin.tinfoil_init(tinfoil)
  73. if not registered:
  74. logger.error("No commands registered - missing plugins?")
  75. sys.exit(1)
  76. args = parser.parse_args(unparsed_args, namespace=global_args)
  77. if getattr(args, 'parserecipes', False):
  78. tinfoil.config_data.disableTracking()
  79. tinfoil.parse_recipes()
  80. tinfoil.config_data.enableTracking()
  81. return args.func(args)
  82. finally:
  83. tinfoil.shutdown()
  84. if __name__ == "__main__":
  85. try:
  86. ret = main()
  87. except bb.BBHandledException:
  88. ret = 1
  89. except Exception:
  90. ret = 1
  91. import traceback
  92. traceback.print_exc()
  93. sys.exit(ret)