Example #1
0
def _main(popts):
    register_commands()

    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 = get_command('help')()
        cmd.run(Context(cmd, [], 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 get_command_names():
            raise UsageException("%s: Error: unknown command %s" % (SCRIPT_NAME, cmd_name))
        else:
            check_command_dependencies(cmd_name)
            run_cmd(cmd_name, cmd_opts)
Example #2
0
def check_command_dependencies(cmd_name):
    # FIXME: temporary hack to inform the user, handle command dependency
    # automatically at some point
    if cmd_name == "build":
        configure_cmd = get_command("configure")
        if not configure_cmd.has_run():
            raise UsageException("""\
The project was not configured: you need to run 'bentomaker configure' first""")
        if not configure_cmd.up_to_date():
            raise UsageException("""\
The project configuration has changed. You need to re-run 'bentomaker configure' first""")
    elif cmd_name in ["install", "build_egg", "build_wininst"]:
        build_cmd = get_command("build")
        if not build_cmd.has_run():
            raise UsageException("""\
The project was not built: you need to 'bentomaker build' first""")
        built_config = _read_argv_checksum("build")
        configured_config = _read_argv_checksum("configure")
        if built_config != configured_config:
            raise UsageException("""\
The project was reconfigured: you need to re-run 'bentomaker build' before \
installing""")
Example #3
0
    def run(self, ctx):
        pprint('BLUE', "Distcheck...")
        bentomaker_script = os.path.abspath(sys.argv[0])
        if sys.platform == "win32":
            bentomaker_script = [sys.executable, bentomaker_script]
        else:
            bentomaker_script = [bentomaker_script]

        pprint('PINK', "\t-> Running sdist...")
        sdist = get_command("sdist")()
        sdist.run(ctx)
        tarname = sdist.tarname
        tardir = sdist.topdir

        saved = os.getcwd()
        if os.path.exists(DISTCHECK_DIR):
            shutil.rmtree(DISTCHECK_DIR)
        os.makedirs(DISTCHECK_DIR)
        target = os.path.join(DISTCHECK_DIR,
                              os.path.basename(tarname))
        rename(tarname, target)
        tarname = os.path.basename(target)

        os.chdir(DISTCHECK_DIR)
        try:
            pprint('PINK', "\t-> Extracting sdist...")
            tarball = tarfile.TarFile.gzopen(tarname)
            tarball.extractall()
            os.chdir(tardir)

            pprint('PINK', "\t-> Configuring from sdist...")
            check_call(bentomaker_script + ["configure", "--prefix=%s" % os.path.abspath("tmp")])

            pprint('PINK', "\t-> Building from sdist...")
            check_call(bentomaker_script + ["build", "-i"])

            pprint('PINK', "\t-> Building egg from sdist...")
            check_call(bentomaker_script + ["build_egg"])

            if sys.platform == "win32":
                pprint('PINK', "\t-> Building wininst from sdist...")
                check_call(bentomaker_script + ["build_wininst"])

            if "test" in get_command_names():
                pprint('PINK', "\t-> Testing from sdist...")
                try:
                    check_call(bentomaker_script + ["test"])
                except CalledProcessError, e:
                    raise CommandExecutionFailure(
                            "test command failed")
            else:
Example #4
0
def run_cmd(cmd_name, cmd_opts):
    root = bento.core.node.Node("", None)
    top = root.find_dir(os.getcwd())

    cmd = get_command(cmd_name)()
    if get_command_override(cmd_name):
        cmd_funcs = get_command_override(cmd_name)
    else:
        cmd_funcs = [(cmd.run, top.abspath())]

    if not os.path.exists(BENTO_SCRIPT):
        raise UsageException("Error: no %s found !" % BENTO_SCRIPT)

    pkg_cache = CachedPackage()
    try:
        package_options = pkg_cache.get_options(BENTO_SCRIPT)
    finally:
        pkg_cache.close()
    cmd.setup_options_parser(package_options)

    if cmd_name == "configure":
        # FIXME: this whole dance to get the user-given flag values is insane
        from bento.commands.configure import set_flag_options
        o, a = cmd.parser.parse_args(cmd_opts)
        flag_values = set_flag_options(cmd.flag_opts, o)
    else:
        flag_values = None
    pkg_cache = CachedPackage()
    try:
        pkg = pkg_cache.get_package(BENTO_SCRIPT, flag_values)
    finally:
        pkg_cache.close()

    if cmd_name == "configure":
        ctx = ConfigureContext(cmd, cmd_opts, pkg, top)
    elif cmd_name == "build":
        ctx = BuildContext(cmd, cmd_opts, pkg, top)
    else:
        ctx = Context(cmd, cmd_opts, pkg, top)

    try:
        spkgs = pkg.subpackages

        def get_subpackage(local_node):
            rpath = local_node.path_from(top)
            k = os.path.join(rpath, "bento.info")
            if local_node == top:
                return pkg
            else:
                if k in spkgs:
                    return spkgs[k]
                else:
                    return None
        def set_local_ctx(ctx, hook, local_dir):
            local_node = top.find_dir(
                    relpath(local_dir, top.abspath()))
            spkg = get_subpackage(local_node)
            ctx.local_dir = local_dir
            ctx.local_node = local_node
            ctx.top_node = top
            ctx.local_pkg = spkg
            ctx.pkg = pkg
            return hook(ctx)

        if get_pre_hooks(cmd_name) is not None:
            for hook, local_dir, help_bypass in get_pre_hooks(cmd_name):
                if not ctx.help and help_bypass:
                    set_local_ctx(ctx, hook, local_dir)

        while cmd_funcs:
            cmd_func, local_dir = cmd_funcs.pop(0)
            set_local_ctx(ctx, cmd_func, local_dir)

        if get_post_hooks(cmd_name) is not None:
            for hook, local_dir, help_bypass in get_post_hooks(cmd_name):
                if not ctx.help and help_bypass:
                    set_local_ctx(ctx, hook, local_dir)
        cmd.shutdown(ctx)
    finally:
        ctx.store()