Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)