ting which supports utf-8.\nPython can't change the filesystem locale after loading so we need a utf-8 when python starts or things won't work.") context = Context(fixed_setup=False) # Default basepath basepath = os.path.dirname(os.path.abspath(__file__)) parser = argparse_oe.ArgumentParser(description="OpenEmbedded development tool", add_help=False, epilog="Use %(prog)s <subcommand> --help to get help on a specific command") parser.add_argument('--basepath', help='Base directory of SDK / build directory') parser.add_argument('--bbpath', help='Explicitly specify the BBPATH, rather than getting it from the metadata') parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true') parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true') parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR') global_args, unparsed_args = parser.parse_known_args() # Help is added here rather than via add_help=True, as we don't want it to # be handled by parse_known_args() parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS, help='show this help message and exit') if global_args.debug: logger.setLevel(logging.DEBUG) elif global_args.quiet: logger.setLevel(logging.ERROR) if global_args.basepath: # Override basepath = global_args.basepath if os.path.exists(os.path.join(basepath, '.devtoolbase')): context.fixed_setup = True else: pth = basepath while pth != '' and pth != os.sep: if os.path.exists(os.path.join(pth, '.devtoolbase')): context.fixed_setup = True basepath = pth break pth = os.path.dirname(pth) if not context.fixed_setup: basepath = os.environ.get('BUILDDIR') if not basepath: logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)") sys.exit(1) logger.debug('Using basepath %s' % basepath) config = ConfigHandler(os.path.join(basepath, 'conf', 'devtool.conf')) if not config.read(): return -1 context.config = config bitbake_subdir = config.get('General', 'bitbake_subdir', '') if bitbake_subdir: # Normally set for use within the SDK logger.debug('Using bitbake subdir %s' % bitbake_subdir) sys.path.insert(0, os.path.join(basepath, bitbake_subdir, 'lib')) core_meta_subdir = config.get('General', 'core_meta_subdir') sys.path.insert(0, os.path.join(basepath, core_meta_subdir, 'lib')) else: # Standard location import scriptpath bitbakepath = scriptpath.add_bitbake_lib_path() if not bitbakepath: logger.error("Unable to find bitbake by searching parent directory of this script or PATH") sys.exit(1) logger.debug('Using standard bitbake path %s' % bitbakepath) scriptpath.add_oe_lib_path() scriptutils.logger_setup_color(logger, global_args.color) if global_args.bbpath is None: try: tinfoil = setup_tinfoil(config_only=True, basepath=basepath) try: global_args.bbpath = tinfoil.config_data.getVar('BBPATH') finally: tinfoil.shutdown() except bb.BBHandledException: return 2 # Search BBPATH first to allow layers to override plugins in scripts_path for path in global_args.bbpath.split(':') + [scripts_path]: pluginpath = os.path.join(path, 'lib', 'devtool') scriptutils.load_plugins(logger, plugins, pluginpath) subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>') subparsers.required = True subparsers.add_subparser_group('sdk', 'SDK maintenance', -2) subparsers.add_subparser_group('advanced', 'Advanced', -1) subparsers.add_subparser_group('starting', 'Beginning work on a recipe', 100) subparsers.add_subparser_group('info', 'Getting information') subparsers.add_subparser_group('working', 'Working on a recipe in the workspace') subparsers.add_subparser_group('testbuild', 'Testing changes on target') if not context.fixed_setup: parser_create_workspace = subparsers.add_parser('create-workspace', help='Set up workspace in an alternative location', description='Sets up a new workspace. NOTE: other devtool subcommands will create a workspace automatically as needed, so you only need to use %(prog)s if you want to specify where the workspace should be located.', group='advanced') parser_create_workspace.add_argument('layerpath', nargs='?', help='Path in which the workspace layer should be created') parser_create_workspace.add_argument('--create-only', action="store_true", help='Only create the workspace layer, do not alter configuration') parser_create_workspace.set_defaults(func=create_workspace, no_workspace=True) for plugin in plugins: if hasattr(plugin, 'register_commands'): plugin.register_commands(subparsers, context) args = parser.parse_args(unparsed_args, namespace=global_args) if not getattr(args, 'no_workspace', False): read_workspace() try: ret = args.func(args, config, basepath, workspace) except DevtoolError as err: if str(err): logger.error(str(err)) ret = err.exitcode except argparse_oe.ArgumentUsageError as ae: parser.error_subcommand(ae.message, ae.subcommand) return ret if __name__ == "__main__": try: ret = main() except Exception: ret = 1 import traceback traceback.print_exc() sys.exit(ret)