Esempio n. 1
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)
Esempio n. 2
0
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()
Esempio n. 3
0
def register_stuff():
    register_commands()
    for cmd_name in COMMANDS_REGISTRY.get_command_names():
        register_options(cmd_name)
    register_options_special()
    register_command_contexts()