Beispiel #1
0
def run():
    """Run hitch bootstrap CLI"""
    def stop_everything(sig, frame):
        """Exit hitch."""
        exit(1)

    signal.signal(signal.SIGINT, stop_everything)
    signal.signal(signal.SIGTERM, stop_everything)
    signal.signal(signal.SIGHUP, stop_everything)
    signal.signal(signal.SIGQUIT, stop_everything)

    if hitchdir.hitch_exists():
        if not path.exists(path.join(hitchdir.get_hitch_directory(), "virtualenv", "bin")):
            stderr.write("Hitch was initialized in this directory (or one above it), but something.\n")
            stderr.write("was corrupted. Try running 'hitch clean' and then run 'hitch init' again.")
            stderr.flush()
            exit(1)

        # Get packages from bin folder that are hitch related
        python_bin = path.join(hitchdir.get_hitch_directory(), "virtualenv", "bin", "python")
        packages = [
            package.replace("hitch", "") for package in listdir(
                path.join(hitchdir.get_hitch_directory(), "virtualenv", "bin")
            )
            if package.startswith("hitch") and package != "hitch"
        ]

        # Add packages that start with hitch* to the list of commands available
        for package in packages:
            cmd = copy.deepcopy(runpackage)
            cmd.name = package
            try:
                description = check_output([
                    python_bin, '-c',
                    'import sys;sys.stdout.write(__import__("hitch{}").commandline.cli.help)'.format(
                        package
                    )
                ]).decode('utf8')
            except CalledProcessError:
                description = ""
            cmd.help = description
            cmd.short_help = description
            cli.add_command(cmd)


        cli.add_command(install)
        cli.add_command(uninstall)
        cli.add_command(upgrade)
        cli.add_command(clean)
        cli.add_command(freeze)
        cli.add_command(init)
        cli.help = "Hitch test runner for:\n\n  {0}.".format(hitchdir.get_hitch_directory())
    else:
        cli.add_command(init)
        cli.add_command(clean)
        cli.help = "Hitch bootstrapper - '.hitch' directory not detected here."
    cli()
Beispiel #2
0
def run():
    """Run hitch bootstrap CLI"""
    signal.signal(signal.SIGINT, stop_everything)
    signal.signal(signal.SIGTERM, stop_everything)
    signal.signal(signal.SIGHUP, stop_everything)
    signal.signal(signal.SIGQUIT, stop_everything)

    if hitchdir.hitch_exists():
        # Get packages from bin folder that are hitch related
        python_bin = path.join(hitchdir.get_hitch_directory(), "virtualenv",
                               "bin", "python")
        if path.exists(python_bin):
            packages = [
                package.replace("hitch", "") for package in listdir(
                    path.join(hitchdir.get_hitch_directory(), "virtualenv",
                              "bin"))
                if package.startswith("hitch") and package != "hitch"
            ]

            # Add commands that start with "hitch" to the list of commands available (e.g. hitchtest, hitchsmtp)
            for package in packages:
                cmd = copy.deepcopy(runpackage)
                cmd.name = package
                try:
                    description = check_output([
                        python_bin, '-c',
                        'import sys;sys.stdout.write(__import__("hitch{0}").commandline.cli.help)'
                        .format(package)
                    ]).decode('utf8')
                except CalledProcessError:
                    description = ""
                cmd.help = description
                cmd.short_help = description
                cli.add_command(cmd)

            cli.add_command(install)
            cli.add_command(uninstall)
            cli.add_command(upgrade)
            cli.add_command(freeze)
        else:
            stderr.write(languagestrings.SOMETHING_CORRUPTED)

        cli.add_command(clean)
        cli.add_command(cleanpkg)
        cli.add_command(init)
        cli.help = "Hitch test runner for:\n\n  {0}.".format(
            hitchdir.get_hitch_directory())
    else:
        cli.add_command(init)
        cli.add_command(clean)
        cli.add_command(cleanpkg)
        cli.help = "Hitch bootstrapper - '.hitch' directory not detected here."
    cli()
Beispiel #3
0
def runpackage(arguments):
    # Generic method to run any installed app in the virtualenv whose name starts with hitch*
    update_requirements()
    binfile = path.join(hitchdir.get_hitch_directory(), "virtualenv", "bin", "hitch{}".format(argv[1]))
    command = [binfile, ] + argv[2:]

    # When receiving an exit signal, just forward it to process child.
    def forward_signal_to_child(pid, signum, frame):
        kill(pid, signum)

    process = Popen(command)
    signal.signal(signal.SIGINT, partial(forward_signal_to_child, process.pid))
    signal.signal(signal.SIGTERM, partial(forward_signal_to_child, process.pid))
    signal.signal(signal.SIGHUP, partial(forward_signal_to_child, process.pid))
    signal.signal(signal.SIGQUIT, partial(forward_signal_to_child, process.pid))
    return_code = process.wait()
    exit(return_code)
Beispiel #4
0
def runpackage(arguments):
    # Generic method to run any installed app in the virtualenv whose name starts with hitch*
    hitchdir.check_hitch_directory_integrity()
    update_requirements()
    binfile = path.join(hitchdir.get_hitch_directory(), "virtualenv", "bin",
                        "hitch{0}".format(argv[1]))
    command = [
        binfile,
    ] + argv[2:]

    # When receiving an exit signal, just forward it to process child.
    def forward_signal_to_child(pid, signum, frame):
        kill(pid, signum)

    process = Popen(command)
    signal.signal(signal.SIGINT, partial(forward_signal_to_child, process.pid))
    signal.signal(signal.SIGTERM, partial(forward_signal_to_child,
                                          process.pid))
    signal.signal(signal.SIGHUP, partial(forward_signal_to_child, process.pid))
    signal.signal(signal.SIGQUIT, partial(forward_signal_to_child,
                                          process.pid))
    return_code = process.wait()
    exit(return_code)