예제 #1
0
    def test_pipe_stderr(self, capfd):
        from plumbum.cmd import cat, head
        cat['/dev/urndom'] & FG(1)
        assert 'urndom' in capfd.readouterr()[1]

        assert '' == capfd.readouterr()[1]

        (cat['/dev/urndom'] | head['-c', '10']) & FG(retcode=1)
        assert 'urndom' in capfd.readouterr()[1]
예제 #2
0
    def test_pipe_stderr(self, capfd):
        from plumbum.cmd import cat, head

        cat["/dev/urndom"] & FG(1)
        assert "urndom" in capfd.readouterr()[1]

        assert "" == capfd.readouterr()[1]

        (cat["/dev/urndom"] | head["-c", "10"]) & FG(retcode=1)
        assert "urndom" in capfd.readouterr()[1]
예제 #3
0
        def run_docker_command(command):
            local["bash"]["-c", utils.get_ecr_login_string()] & FG

            aws_creds = []
            if local.env.get("ON_AWS", "0") == "0":
                aws_creds = [
                    f"--env",
                    f"AWS_ACCESS_KEY_ID={local.env['AWS_ACCESS_KEY_ID']}",
                    f"--env",
                    f"AWS_SECRET_ACCESS_KEY={local.env['AWS_SECRET_ACCESS_KEY']}",
                    f"--env",
                    f"AWS_DEFAULT_REGION={local.env['AWS_DEFAULT_REGION']}",
                ]

            local["docker"][
                [
                    f"run",
                    f"-it",
                    *aws_creds,
                    f"--mount",
                    f"type=bind,source={lnfit_path},target=/lnfit",
                    f"188029688209.dkr.ecr.us-east-1.amazonaws.com/alex:latest",
                    f"bash",
                    f"-c",
                    command,
                ]
            ] & FG(retcode=None)
예제 #4
0
    def run_tests(self, experiment, run):
        exp = experiment(self.run_f)

        pg_ctl = local[path.join(self.builddir, "pg_ctl")]
        dropdb = local[path.join(self.builddir, "dropdb")]
        createdb = local[path.join(self.builddir, "createdb")]
        pgbench = local[path.join(self.builddir, "pgbench")]

        bin_name = path.join(self.builddir, self.name + ".sh")
        test_data = path.join(self.testdir, "test-data")

        (echo["#!/bin/sh"] >> bin_name)()
        (echo[str(exp)] >> bin_name)()
        chmod("+x", bin_name)

        num_clients = 1
        num_transactions = 1000000

        pg_ctl("stop", "-t", 360, "-w", "-D", test_data, retcode=None)
        try:
            with local.cwd(test_data):
                pg_ctl("start", "-p", bin_name, "-w", "-D", test_data)
            dropdb["pgbench"] & FG(retcode=None)
            createdb("pgbench")
            run(pgbench["-i", "pgbench"])
            run(pgbench["-c", num_clients, "-S", "-t", num_transactions,
                        "pgbench"])
            dropdb("pgbench")
            pg_ctl("stop", "-t", 360, "-w", "-D", test_data)
        except Exception:
            pg_ctl("stop", "-t", 360, "-w", "-D", test_data)
            raise
예제 #5
0
def install_package(pkg_name):
    if not bool(CFG['bootstrap']['install']):
        return False

    if pkg_name not in PACKAGES:
        print("No bootstrap support for package '{0}'".format(pkg_name))
    linux, _, _ = linux_distribution_major()
    linux = str(linux.lower())
    package_manager = PACKAGE_MANAGER[linux]
    packages = PACKAGES[pkg_name][linux]
    for pkg_name_on_host in packages:
        print("You are missing the package: '{0}'".format(pkg_name_on_host))
        cmd = local["sudo"]
        cmd = cmd[package_manager["cmd"], package_manager["args"],
                  pkg_name_on_host]
        cmd_str = str(cmd)

        ret = False
        if ui.ask("Run '{cmd}' to install it?".format(cmd=cmd_str)):
            print("Running: '{cmd}'".format(cmd=cmd_str))

        try:
            (cmd & FG(retcode=0))
        except ProcessExecutionError:
            print("NOT INSTALLED")
        else:
            print("OK")
    return ret
예제 #6
0
def install_linux(dist: str, arch: str, version: str = ''):
    from plumbum.cmd import tar, proot, pv, curl, bash

    distinfo, url, version = format_url(dist, arch, version)

    os.chdir(atilo_tmp)
    release_name = dist + version
    root = os.path.join(atilo_home, release_name)
    os.makedirs(root, exist_ok=True)

    tip('[ Downloading ... ]')
    if os.path.exists(release_name):
        tip('[ Skip download ]')
    else:
        print(url)
        curl[url, '-o', release_name, '--progress', '-L', '-C', '-'] & FG

    tip('[ Extracting ... ]')
    if 'fedora' in release_name:
        tar['xf', release_name, '--skip-components=1', '--exclude', 'json',
            '--exclude', 'VERSION'] & FG(retcode=None)
        (pv['layer.tar'] | proot['tar', 'xpC', root]) & FG(retcode=None)
        rm['-f', 'layer.tar'] & FG
        chmod['+w', root] & FG
    else:
        tararg = '{}C'.format(distinfo['zip'])
        if proot['--link2symlink', 'ls'] & TF:
            (pv[release_name]
             | proot['--link2symlink', 'tar', tararg, root]) & FG(retcode=None)
        else:
            tip("extract without --link2symlink")
            (pv[release_name] | proot['tar', tararg, root]) & FG(retcode=None)

    tip('[ Configuring ... ]')
    resolvconf = os.path.join(root, 'etc/resolv.conf')
    (echo[name_servers] > resolvconf)()
    profile = os.path.join(root, 'etc/profile')
    (echo['export USER=root'] >> profile)()

    script = create_start_script(release_name, distinfo.get('sh', '/bin/bash'))

    tip('[ Updating ... ]')
    bash[script, distinfo['update']] & FG(retcode=None)

    tip('[ All done ... ]')
    tip('{} To start'.format(script))
예제 #7
0
def call(cmd):
    base_cmd = local
    for part in cmd.split():
        if '$' in part:
            part = local.env[part.replace('$', '')]
            for subpart in part.split():
                base_cmd = base_cmd[subpart]
        else:
            base_cmd = base_cmd[part]
    # Execute cmd in FG with tty redirection, ignore exit code
    base_cmd & FG(None)
예제 #8
0
def mat_compress(infile, outfile, timeout=None):
    try:
        mtlbeng.workspace['in_file'] = infile
        mtlbeng.workspace['out_file'] = outfile
        mtlbeng.matCompress(nargout=0)
    # pretty stupid, FIXME
    except (NameError, AttributeError):
        print('Failed to use MATLAB python API')
        print('Falling back to command line matlab')
        with local.cwd(MATLAB_DIR):
            cmd = "in_file='%s';out_file='%s';matCompress" % (infile, outfile)
            return matlab_nogui[cmd] & FG(timeout=timeout)
예제 #9
0
def retry(pb_cmd, retries=0, max_retries=10, retcode=0, retry_retcodes=None):
    try:
        pb_cmd & FG(retcode=retcode)
    except ProcessExecutionError as proc_ex:
        new_retcode = proc_ex.retcode
        if retries > max_retries:
            LOG.error("Retried %d times. No change. Abort", retries)
            raise

        if new_retcode in retry_retcodes:
            retry(
                pb_cmd,
                retries=retries + 1,
                max_retries=max_retries,
                retcode=retcode,
                retry_retcodes=retry_retcodes)
        else:
            raise
예제 #10
0
파일: main.py 프로젝트: erisyon/plaster
    def run_zests_v2(self, cli_args, debug_mode):
        tell(f"Running zests v2...")

        # as os.environ is evaluated when it is first imported
        # we can't use any of the more graceful ways to set the environment
        with local.env(RUN_ENV="test", ZAP_DEBUG_MODE=debug_mode):
            zest_version = None
            try:
                from zest.version import __version__ as zest_version
            except ImportError:
                pass

            assert zlog.config_dict is not None
            assert zest_version.startswith("1.1.")
            with tmp.tmp_file() as tmp_path:
                with open(tmp_path, "w") as f:
                    f.write(json.dumps(zlog.config_dict))

                # cli_args += ["--logger_config_json", tmp_path]
                local["python"]["-u", "-m", "zest.zest_cli"].bound_command(
                    *cli_args) & FG(retcode=None)