recipetool 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env python
  2. # Recipe creation tool
  3. #
  4. # Copyright (C) 2014 Intel Corporation
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License version 2 as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. import sys
  19. import os
  20. import argparse
  21. import glob
  22. import logging
  23. scripts_path = os.path.dirname(os.path.realpath(__file__))
  24. lib_path = scripts_path + '/lib'
  25. sys.path = sys.path + [lib_path]
  26. import scriptutils
  27. logger = scriptutils.logger_create('recipetool')
  28. plugins = []
  29. def tinfoil_init():
  30. import bb.tinfoil
  31. import logging
  32. tinfoil = bb.tinfoil.Tinfoil()
  33. tinfoil.prepare(True)
  34. for plugin in plugins:
  35. if hasattr(plugin, 'tinfoil_init'):
  36. plugin.tinfoil_init(tinfoil)
  37. tinfoil.logger.setLevel(logging.WARNING)
  38. def main():
  39. if not os.environ.get('BUILDDIR', ''):
  40. logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
  41. sys.exit(1)
  42. parser = argparse.ArgumentParser(description="OpenEmbedded recipe tool",
  43. epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
  44. parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
  45. parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
  46. parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
  47. subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
  48. scriptutils.load_plugins(logger, plugins, os.path.join(scripts_path, 'lib', 'recipetool'))
  49. registered = False
  50. for plugin in plugins:
  51. if hasattr(plugin, 'register_command'):
  52. registered = True
  53. plugin.register_command(subparsers)
  54. if not registered:
  55. logger.error("No commands registered - missing plugins?")
  56. sys.exit(1)
  57. args = parser.parse_args()
  58. if args.debug:
  59. logger.setLevel(logging.DEBUG)
  60. elif args.quiet:
  61. logger.setLevel(logging.ERROR)
  62. import scriptpath
  63. bitbakepath = scriptpath.add_bitbake_lib_path()
  64. if not bitbakepath:
  65. logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
  66. sys.exit(1)
  67. logger.debug('Found bitbake path: %s' % bitbakepath)
  68. scriptutils.logger_setup_color(logger, args.color)
  69. tinfoil_init()
  70. ret = args.func(args)
  71. return ret
  72. if __name__ == "__main__":
  73. try:
  74. ret = main()
  75. except Exception:
  76. ret = 1
  77. import traceback
  78. traceback.print_exc(5)
  79. sys.exit(ret)