How to use the plumbum.local function in plumbum

To help you get started, we’ve selected a few plumbum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tomerfiliba / plumbum / tests / test_config.py View on Github external
def test_home(self):
        mypath = local.env.home /  'some_simple_home_rc.ini'
        assert not mypath.exists()
        try:
            with Config('~/some_simple_home_rc.ini') as conf:
                conf['a'] = 'b'
            assert mypath.exists()
            mypath.unlink()

            with Config(mypath) as conf:
                conf['a'] = 'b'
            assert mypath.exists()
            mypath.unlink()

        finally:
            mypath.unlink()
github tomerfiliba / plumbum / experiments / test_parallel.py View on Github external
def test_parallel(self):
        m = Cluster(local, local)
        import time

        t = time.time()
        ret = m["sleep"]("2")
        assert len(ret) == 2
        assert 2 <= time.time() - t < 4
github tomerfiliba / plumbum / tests / test_remote.py View on Github external
def test_sshpass(self):
        with local.as_root():
            local["useradd"]("-m", "-b", "/tmp", "testuser")

        try:
            with local.as_root():
                try:
                    (local["passwd"] << "123456")("--stdin", "testuser")
                except ProcessExecutionError:
                    # some versions of passwd don't support --stdin, nothing to do in this case
                    logging.warn("passwd failed")
                    return

            with SshMachine("localhost", user = "testuser", password = "123456") as rem:
                assert rem["pwd"]().strip() == "/tmp/testuser"
        finally:
            with local.as_root():
                local["userdel"]("-r", "testuser")
github Refinitiv / ngx_http_websocket_stat_module / test / build_helper.py View on Github external
def make_nginx(links):
    nginx_fn = getLinkFilename(links["nginx"])
    nginx_dir = getLinkDir(links["nginx"])
    local.cwd.chdir(nginx_dir)
    conf_cmd = local["./configure"]["--with-pcre=" + os.path.join(this_dir, getLinkDir(links["pcre"])),
                    "--with-zlib=" + os.path.join(this_dir, getLinkDir(links["zlib"])),
                    "--with-http_stub_status_module",
                    "--with-openssl=" + os.path.join(this_dir, getLinkDir(links["openssl"])),
                    "--add-module=../nginx_upstream_check_module-master",
                    "--with-http_ssl_module",
                    "--with-file-aio",
                    "--with-http_addition_module",
                    "--with-http_auth_request_module",
                    "--with-http_dav_module",
                    "--with-http_degradation_module",
                    "--with-http_flv_module",
                    "--with-http_gunzip_module",
                    "--with-http_gzip_static_module",
                    "--with-http_random_index_module",
                    "--with-http_realip_module",
github tomerfiliba / rpyc / rpyc / utils / zerodeploy.py View on Github external
def __init__(self, remote_machine, server_class="rpyc.utils.server.ThreadedServer",
                 extra_setup="", python_executable=None):
        self.proc = None
        self.tun = None
        self.remote_machine = remote_machine
        self._tmpdir_ctx = None

        rpyc_root = local.path(rpyc.__file__).up()
        self._tmpdir_ctx = remote_machine.tempdir()
        tmp = self._tmpdir_ctx.__enter__()
        copy(rpyc_root, tmp / "rpyc")

        script = (tmp / "deployed-rpyc.py")
        modname, clsname = server_class.rsplit(".", 1)
        script.write(SERVER_SCRIPT.replace("$MODULE$", modname).replace(
            "$SERVER$", clsname).replace("$EXTRA_SETUP$", extra_setup))
        if isinstance(python_executable, BoundCommand):
            cmd = python_executable
        elif python_executable:
            cmd = remote_machine[python_executable]
        else:
            major = sys.version_info[0]
            minor = sys.version_info[1]
            cmd = None
github brython-dev / brython / scripts / commands / lib / git.py View on Github external
"""
    Miscellaneous utility functions to deal with the git repository
"""
import pathlib

from plumbum import local


GIT = local['git']

_GIT_INDEX = (pathlib.Path(__file__).parent.parent.parent.parent/'.git'/'index').read_bytes()


def in_git(p):
    """
        Returns true if the given path is under version control.
    """
    return str(p).encode('ascii', 'ignore') in _GIT_INDEX


def head_commit_sha():
    """
        Returns the commit id of HEAD
    """
    return str(GIT("show", "--format=%h", "-q", "HEAD")).strip()
github weka-io / easypy / easypy / sync.py View on Github external
def do_signal(raised_exc):
        global LAST_ERROR
        if LAST_ERROR is not raised_exc:
            _logger.debug("MainThread took the exception - we're done here")
            if use_concurrent_loop:
                raiser.stop()
            return

        _logger.info("Raising %s in main thread", type(LAST_ERROR))
        local.cmd.kill("-%d" % REGISTERED_SIGNAL, pid)
github tomerfiliba / plumbum / experiments / parallel.py View on Github external
if __name__ == "__main__":
    from plumbum import local
    from plumbum.cmd import ls, date, sleep
    c = ls & date & sleep[1]
    print(c())

    c = ls & date & sleep[1] & sleep["-z"]
    try:
        c()
    except ProcessExecutionError as ex:
        print(ex)
    else:
        assert False

    clst = Cluster(local, local, local)
    print(clst["ls"]())


    # This works fine
    print(local.session().run("echo $$"))

    # this does not
    ret, stdout, stderr = clst.session().run("echo $$")
    print(ret)
    ret = [int(pid) for pid in stdout]
    assert(len(set(ret))==3)
github michaeljoseph / changes / changes / verification.py View on Github external
def get_test_runner():
    test_runners = ['tox', 'nosetests', 'py.test']
    test_runner = None
    for runner in test_runners:
        try:
            test_runner = local[runner]
        except CommandNotFound:
            continue
    return test_runner
github atareao / national-geographic-wallpaper / src / comun.py View on Github external
def is_running(process):
    ps = local['ps']
    result = ps['asw']()
    return re.search(process, result)