Example #1
0
def sudo(cmd, user=None, capture=True, remote_only=False, **kwargs):
    capture = parse_bool(capture)

    if dconf.HOST_CONN == 'remote':
        res = _sudo(cmd, user=user, **kwargs)

    elif dconf.HOST_CONN == 'local':
        pre_cmd = 'sudo '
        if user:
            pre_cmd += '-u {} '.format(user)
        res = local(pre_cmd + cmd, capture=capture, **kwargs)

    else:  # docker or remote_docker
        user = user or 'root'
        opts = '-ti -u {}'.format(user or 'root')
        if user == 'root':
            opts += ' -w /'
        if remote_only:
            docker_cmd = cmd
        else:
            docker_cmd = 'docker exec {} {} /bin/bash -c "{}"'.format(
                opts, dconf.CONTAINER_NAME, cmd)
        if dconf.HOST_CONN == 'docker':
            res = local(docker_cmd, capture=capture, **kwargs)
        elif dconf.HOST_CONN == 'remote_docker':
            res = _sudo(docker_cmd, **kwargs)
        else:
            raise Exception('wrong HOST_CONN type {}'.format(dconf.HOST_CONN))
    return res
def sudo(cmd, verbose=False):
    if verbose:
        with settings(warn_only=True):
            return _sudo(cmd)
    else:
        # Otherwise, be quiet
        with settings(hide("everything"), warn_only=True):
            return _sudo(cmd)
Example #3
0
def sudo(command, quiet=False, show=True):
    """ Runs a command as sudo. """
    if show:
        print_command(command, sudo=True)

    with hide("running"):
        return _sudo(command, quiet=quiet)
Example #4
0
def sudo(command, show=True):
    """ Runs a command as sudo. """
    if show:
        print_command(command)

    with hide("running"):
        return _sudo(command)
Example #5
0
def sudo(command, show=True):
    """ Runs a command as sudo. """
    if show:
        print_command(command)

    with hide("running"):
        return _sudo(command)
Example #6
0
def sudo(command, show=True, *args, **kwargs):
    """
    Runs a command as sudo on the remote server.
    """
    if show:
        print_command(command)
    with hide("running"):
        return _sudo(command, *args, **kwargs)
Example #7
0
def sudo(command, show=True, **kwargs):
    """
    Runs a command as sudo.
    """
    if show:
        print_command(command, prompt='#')
    with hide("running"):
        return _sudo(command, **kwargs)
Example #8
0
def sudo(command, show=True, *args, **kwargs):
    """
    Runs a command as sudo on the remote server.
    """
    if show:
        print_command(command)
    with hide("running"):
        return _sudo(command, *args, **kwargs)
Example #9
0
def run(command, show=True):
    """ Runs a shell command on the remote server. """
    if show:
        print_command(command)

    with hide("running"):
        if env.deploy_user:
            return _sudo(command, user=env.deploy_user)
        return _run(command)
Example #10
0
def run(command, show=True):
    """ Runs a shell command on the remote server. """
    if show:
        print_command(command)

    with hide("running"):
        if env.deploy_user:
            return _sudo(command, user=env.deploy_user)
        return _run(command)
Example #11
0
def run(command, quiet=False, show=True):
    """ Runs a shell command on the remote server. """
    if show:
        print_command(command)

    with hide("running"):
        if 'deploy_user' in env:
            # If a deploy_user is specified, run as that user
            return _sudo(command, quiet=quiet, user=env.deploy_user)
        return _run(command, quiet=quiet)
Example #12
0
def sudo(command, show=True):
    """
    Runs a command as sudo.
    """
    if show:
        print_command(command)
    if env.have_sudo:
        with hide("running"):
            return _sudo(command)
    else:
        _print('Skipping: %s' % command)
Example #13
0
def is_file(fqfn):
    if fqfn not in _fs_cache['is_file']:
        verbose = common.get_verbose()
        if env.plan_storage == STORAGE_REMOTE:
            cmd = 'if [ -f "%s" ]; then echo 1; else echo 0; fi' % fqfn
            output = _sudo(cmd)
            if verbose:
                print('output:', output)
            ret = int(re.findall(r'^[0-9]+$', output, flags=re.DOTALL|re.I|re.M)[0])
        else:
            ret = os.path.isfile(fqfn)
        _fs_cache['is_file'][fqfn] = ret
    return _fs_cache['is_file'][fqfn]
Example #14
0
def list_dir(d):
    if d not in _fs_cache['list_dir']:
        verbose = common.get_verbose()
        if env.plan_storage == STORAGE_REMOTE:
            #output = sudo_or_dryrun('ls "%s"' % d)
            output = _sudo('ls "%s"' % d)
            output = output.split()
            if verbose:
                print('output:', output)
            ret = output
        else:
            ret = os.listdir(d)
        _fs_cache['list_dir'][d] = ret
    return _fs_cache['list_dir'][d]
Example #15
0
def is_dir(d):
    if d not in _fs_cache['is_dir']:
        verbose = common.get_verbose()
        if env.plan_storage == STORAGE_REMOTE:
            cmd = 'if [ -d "%s" ]; then echo 1; else echo 0; fi' % d
            output = _sudo(cmd)
            if verbose:
                print('output:', output)
            #ret = int(output)
            ret = int(re.findall(r'^[0-9]+$', output, flags=re.DOTALL|re.I|re.M)[0])
        else:
            ret = os.path.isdir(d)
        _fs_cache['is_dir'][d] = ret
    return _fs_cache['is_dir'][d]
Example #16
0
def list_dir(d):
    if d not in _fs_cache['list_dir']:
        verbose = common.get_verbose()
        if env.plan_storage == STORAGE_REMOTE:
            #output = sudo_or_dryrun('ls "%s"' % d)
            output = _sudo('ls "%s"' % d)
            output = output.split()
            if verbose:
                print('output:', output)
            ret = output
        else:
            ret = os.listdir(d)
        _fs_cache['list_dir'][d] = ret
    return _fs_cache['list_dir'][d]
Example #17
0
def is_file(fqfn):
    if fqfn not in _fs_cache['is_file']:
        verbose = common.get_verbose()
        if env.plan_storage == STORAGE_REMOTE:
            cmd = 'if [ -f "%s" ]; then echo 1; else echo 0; fi' % fqfn
            output = _sudo(cmd)
            if verbose:
                print('output:', output)
            ret = int(
                re.findall(r'^[0-9]+$', output,
                           flags=re.DOTALL | re.I | re.M)[0])
        else:
            ret = os.path.isfile(fqfn)
        _fs_cache['is_file'][fqfn] = ret
    return _fs_cache['is_file'][fqfn]
Example #18
0
def is_dir(d):
    if d not in _fs_cache['is_dir']:
        verbose = common.get_verbose()
        if env.plan_storage == STORAGE_REMOTE:
            cmd = 'if [ -d "%s" ]; then echo 1; else echo 0; fi' % d
            output = _sudo(cmd)
            if verbose:
                print('output:', output)
            #ret = int(output)
            ret = int(
                re.findall(r'^[0-9]+$', output,
                           flags=re.DOTALL | re.I | re.M)[0])
        else:
            ret = os.path.isdir(d)
        _fs_cache['is_dir'][d] = ret
    return _fs_cache['is_dir'][d]
Example #19
0
def sudo(cmd, user=None, capture=True, **kwargs):
    capture = parse_bool(capture)

    if dconf.HOST_CONN == 'remote':
        res = _sudo(cmd, user=user, **kwargs)

    elif dconf.HOST_CONN == 'local':
        pre_cmd = 'sudo '
        if user:
            pre_cmd += '-u {} '.format(user)
        res = local(pre_cmd + cmd, capture=capture, **kwargs)

    else:  # docker
        user = user or 'root'
        opts = '-ti -u {}'.format(user or 'root')
        if user == 'root':
            opts += ' -w /'
        res = local('docker exec {} {} /bin/bash -c "{}"'.format(
            opts, dconf.CONTAINER_NAME, cmd),
                    capture=capture)

    return res
def sudo_put(local_path, remote_path, mode=None):
    name = path.basename(remote_path)
    put(local_path, "/tmp/%s" % name, mode)
    _sudo("mv /tmp/%s %s" % (name, remote_path))
Example #21
0
def sudo(*args, **kwargs):
    if env.sudo_user:
        kwargs['user'] = env.sudo_user

    return _sudo(*args, **kwargs)
Example #22
0
def sudo(command, show=True, shell_escape=None, shell=True):
    """Runs a command as sudo on the remote server."""
    if show:
        print_command(command)
    with hide("running"):
        return _sudo(command, shell_escape=shell_escape, shell=shell)
Example #23
0
def sudo(command):
    return _sudo(command)
Example #24
0
def sudo(*args, **kwargs):
    if env.sudo_user:
        kwargs['user'] = env.sudo_user

    return _sudo(*args, **kwargs)