bitbake-layers 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. import signal
  25. bindir = os.path.dirname(__file__)
  26. topdir = os.path.dirname(bindir)
  27. sys.path[0:0] = [os.path.join(topdir, 'lib')]
  28. import bb.tinfoil
  29. import bb.msg
  30. logger = bb.msg.logger_create('bitbake-layers', sys.stdout)
  31. def main():
  32. signal.signal(signal.SIGPIPE, signal.SIG_DFL)
  33. parser = argparse.ArgumentParser(
  34. description="BitBake layers utility",
  35. epilog="Use %(prog)s <subcommand> --help to get help on a specific command",
  36. add_help=False)
  37. parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
  38. parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
  39. parser.add_argument('-F', '--force', help='Force add without recipe parse verification', action='store_true')
  40. parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
  41. global_args, unparsed_args = parser.parse_known_args()
  42. # Help is added here rather than via add_help=True, as we don't want it to
  43. # be handled by parse_known_args()
  44. parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
  45. help='show this help message and exit')
  46. subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
  47. subparsers.required = True
  48. if global_args.debug:
  49. logger.setLevel(logging.DEBUG)
  50. elif global_args.quiet:
  51. logger.setLevel(logging.ERROR)
  52. # Need to re-run logger_create with color argument
  53. # (will be the same logger since it has the same name)
  54. bb.msg.logger_create('bitbake-layers', output=sys.stdout, color=global_args.color)
  55. plugins = []
  56. tinfoil = bb.tinfoil.Tinfoil(tracking=True)
  57. tinfoil.logger.setLevel(logger.getEffectiveLevel())
  58. try:
  59. tinfoil.prepare(True)
  60. for path in ([topdir] +
  61. tinfoil.config_data.getVar('BBPATH').split(':')):
  62. pluginpath = os.path.join(path, 'lib', 'bblayers')
  63. bb.utils.load_plugins(logger, plugins, pluginpath)
  64. registered = False
  65. for plugin in plugins:
  66. if hasattr(plugin, 'register_commands'):
  67. registered = True
  68. plugin.register_commands(subparsers)
  69. if hasattr(plugin, 'tinfoil_init'):
  70. plugin.tinfoil_init(tinfoil)
  71. if not registered:
  72. logger.error("No commands registered - missing plugins?")
  73. sys.exit(1)
  74. args = parser.parse_args(unparsed_args, namespace=global_args)
  75. if getattr(args, 'parserecipes', False):
  76. tinfoil.config_data.disableTracking()
  77. tinfoil.parse_recipes()
  78. tinfoil.config_data.enableTracking()
  79. return args.func(args)
  80. finally:
  81. tinfoil.shutdown()
  82. if __name__ == "__main__":
  83. try:
  84. ret = main()
  85. except bb.BBHandledException:
  86. ret = 1
  87. except Exception:
  88. ret = 1
  89. import traceback
  90. traceback.print_exc()
  91. sys.exit(ret)