def _main(popts, run_node, top_node, build_node): if popts["show_version"]: print bento.__version__ return 0 if popts["show_full_version"]: print bento.__version__ + "git" + bento.__git_revision__ return 0 if popts["show_usage"]: cmd = COMMANDS_REGISTRY.get_command('help')() cmd.run(CmdContext([], OPTIONS_REGISTRY.get_options('help'), None, None)) return 0 cmd_name = popts["cmd_name"] cmd_opts = popts["cmd_opts"] if not cmd_name: print "Type '%s help' for usage." % SCRIPT_NAME return 1 else: if not cmd_name in COMMANDS_REGISTRY.get_command_names(): raise UsageException("%s: Error: unknown command %s" % (SCRIPT_NAME, cmd_name)) else: run_cmd(cmd_name, cmd_opts, run_node, top_node, build_node)
def run_cmd(cmd_name, cmd_opts, run_node, top_node, build_node): cmd_klass = COMMANDS_REGISTRY.get_command(cmd_name) # XXX: fix this special casing (commands which do not need a pkg instance) if cmd_name in ["help", "convert"]: cmd = cmd_klass() options_ctx = OPTIONS_REGISTRY.get_options(cmd_name) ctx_klass = CONTEXT_REGISTRY.get(cmd_name) ctx = ctx_klass(cmd_opts, options_ctx, None, run_node) # XXX: hack for help command to get option context for any command # without making help depends on bentomakerlib ctx.options_registry = OPTIONS_REGISTRY cmd.run(ctx) return bento_info = top_node.find_node(BENTO_SCRIPT) if bento_info is None: raise UsageException("Error: no %s found !" % os.path.join(top_node.abspath(), BENTO_SCRIPT)) package_options = __get_package_options(top_node) pkg = _get_package_with_user_flags(cmd_name, cmd_opts, package_options, top_node, build_node) if is_help_only(cmd_name, cmd_opts): options_context = OPTIONS_REGISTRY.get_options(cmd_name) p = options_context.parser o, a = p.parse_args(cmd_opts) if o.help: p.print_help() else: run_dependencies(cmd_name, run_node, top_node, build_node, pkg) ctx_klass = CONTEXT_REGISTRY.get(cmd_name) run_cmd_in_context(cmd_klass, cmd_name, cmd_opts, ctx_klass, run_node, top_node, pkg) cmd_data_db = build_node.make_node(CMD_DATA_DUMP) _set_cmd_data_provider(cmd_name, cmd_opts, cmd_data_db)
def run_dependencies(cmd_name, run_node, top_node, build_node, pkg): cmd_data_db = build_node.make_node(CMD_DATA_DUMP) deps = CMD_SCHEDULER.order(cmd_name) for cmd_name in deps: cmd_klass = COMMANDS_REGISTRY.get_command(cmd_name) cmd_argv = _get_cmd_data_provider(cmd_data_db).get_argv(cmd_name) ctx_klass = CONTEXT_REGISTRY.get(cmd_name) run_cmd_in_context(cmd_klass, cmd_name, cmd_argv, ctx_klass, run_node, top_node, pkg)
def _wrapped_main(popts, run_node, top_node, build_node): def _big_ugly_hack(): # FIXME: huge ugly hack - we need to specify once and for all when the # package info is parsed and available, so that we can define options # and co for commands from bento.commands.configure import _setup_options_parser # FIXME: logic to handle codepaths which work without a bento.info # should be put in one place n = top_node.find_node(BENTO_SCRIPT) if n: package_options = __get_package_options(top_node) _setup_options_parser(OPTIONS_REGISTRY.get_options("configure"), package_options) else: import warnings warnings.warn("No %r file in current directory - not all options " "will be displayed" % BENTO_SCRIPT) return global_context = GlobalContext(COMMANDS_REGISTRY, CONTEXT_REGISTRY, OPTIONS_REGISTRY, CMD_SCHEDULER) mods = set_main(top_node, build_node) if mods: mods[0].startup(global_context) register_stuff() _big_ugly_hack() if mods: mods[0].options(global_context) # FIXME: this registered options for new commands registered in hook. It # should be made all in one place (hook and non-hook) for cmd_name in COMMANDS_REGISTRY.get_command_names(): if not OPTIONS_REGISTRY.is_registered(cmd_name): register_options(cmd_name) try: return _main(popts, run_node, top_node, build_node) finally: if mods: mods[0].shutdown()
def register_stuff(): register_commands() for cmd_name in COMMANDS_REGISTRY.get_command_names(): register_options(cmd_name) register_options_special() register_command_contexts()
def register_options(cmd_name): cmd_klass = COMMANDS_REGISTRY.get_command(cmd_name) usage = cmd_klass.long_descr.splitlines()[1] context = OptionsContext.from_command(cmd_klass, usage=usage) OPTIONS_REGISTRY.register_command(cmd_name, context)
def register_commands(): COMMANDS_REGISTRY.register_command("help", HelpCommand) COMMANDS_REGISTRY.register_command("configure", ConfigureCommand) COMMANDS_REGISTRY.register_command("build", BuildCommand) COMMANDS_REGISTRY.register_command("install", InstallCommand) COMMANDS_REGISTRY.register_command("convert", ConvertCommand) COMMANDS_REGISTRY.register_command("sdist", SdistCommand) COMMANDS_REGISTRY.register_command("build_egg", BuildEggCommand) COMMANDS_REGISTRY.register_command("build_wininst", BuildWininstCommand) COMMANDS_REGISTRY.register_command("distcheck", DistCheckCommand) COMMANDS_REGISTRY.register_command("build_pkg_info", BuildPkgInfoCommand, public=False) COMMANDS_REGISTRY.register_command("parse", ParseCommand, public=False) COMMANDS_REGISTRY.register_command("detect_type", DetectTypeCommand, public=False) if sys.platform == "darwin": import bento.commands.build_mpkg COMMANDS_REGISTRY.register_command("build_mpkg", bento.commands.build_mpkg.BuildMpkgCommand) CMD_SCHEDULER.set_before("build_mpkg", "build")