Ejemplo n.º 1
0
def rm_rf(path):
    ''' Remote the specified path recursively (both files and directories). '''
    removal_path = path

    # If path is not a string but a list of multiple paths,
    # remove them all.
    if is_iterable(path) and not is_string(path):
        removal_path = ' '.join(path)

    return ssh.run('rm -rf {}'.format(removal_path))
Ejemplo n.º 2
0
def diff_files_between(ref1, ref2):
    '''
    Get a list of files changed in between two refs.
    '''
    output = subprocess.check_output([
        'git', 'diff', '--name-only', ref1, ref2
    ])

    if not output or not is_string(output):
        return []

    return output.splitlines()
Ejemplo n.º 3
0
def test_is_string():
    ''' Test is_string() function. '''
    assert is_string('') is True
    assert is_string('Test') is True
    assert is_string("Hello") is True
    assert is_string(u"Hello") is True
    assert is_string(True) is False
    assert is_string(None) is False
Ejemplo n.º 4
0
def run(command, **params):
    '''
    Execute a command or a list of commands on the remote host over SSH.
    '''

    # Keyword args
    raw = params.get('raw') or False
    return_output = params.get('return_output') or True

    # If command is a list of commands,
    # concat the commands and run them all.
    if not is_string(command) and is_iterable(command):
        command = '&& '.join(command)

    # Execute the command and get the IO streams.
    (stdin, stdout, stderr) = remote.run(resolve_client(), command, **params)

    # Return the raw result if raw=True.
    if raw:
        return (stdin, stdout, stderr)

    # If output is required (usually),
    # return a list of each output line.
    if return_output:
        lines = []

        for l in stdout:
            lines.append(l.strip())

        return lines
    # TODO: Error handling and sending out stderr

    # For return_output=False,
    # just walk until the end of the stream
    # and just return without any output.
    for _ in stdout:
        pass