bitbake-layers 4.4 KB

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