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