Exemple #1
0
def test_run_command():
    output = seutils.run_command(['echo', 'test'])
    assert output == ['test\n']
    with pytest.raises(seutils.NonZeroExitCode):
        seutils.run_command(['ls', 'doesnotexist'])
    with pytest.raises(seutils.NoSuchPath):
        seutils.run_command(['cd', 'doesnotexist'],
                            rcodes={1: seutils.NoSuchPath})
Exemple #2
0
def cp(src, dst, n_attempts=seutils.N_COPY_ATTEMPTS, create_parent_directory=True, verbose=True, force=False):
    cmd = [ 'scp', src, dst ]
    if verbose: cmd.insert(1, '-v')
    if create_parent_directory:
        parent_dir = osp.dirname(dst)
        if _is_remote(dst):
            mkdir(parent_dir)
        elif not osp.isdir(parent_dir):
            os.makedirs(osp.dirname(dst))
    run_command(cmd, n_attempts=n_attempts)
Exemple #3
0
def rm(path, recursive):
    mgm, lfn = split_mgm(path)
    if seutils.isdir(path):
        if not recursive:
            raise RuntimeError(
                '{} is a directory but rm instruction is not recursive'.format(
                    path))
    cmd = ['eos', mgm, 'rm', lfn]
    if recursive: cmd.insert(-1, '-r')
    run_command(cmd)
Exemple #4
0
def stat(fullpath):
    server, path = _split_remote(fullpath)
    cmd = [ 'ssh', server, 'ls -ld {0}'.format(path) ]
    output = run_command(cmd)
    contents = []
    for l in output:
        l = l.strip()
        if not len(l): continue
        if not(l.startswith('d') or l.startswith('-')): continue
        return _lsstatline_to_inode(l, server, path)
Exemple #5
0
def listdir_recursive(path):
    """
    Specific for ssh: Flat list of all files in a remote directory
    """
    server, lpath = _split_remote(path)
    cmd = [ 'ssh', server, 'find {0} -printf \'%y %s %A@ %p\n\''.format(lpath) ]
    logger.info('Gathering all inodes recursively in %s', path)
    output = run_command(cmd)
    contents = []
    for l in output:
        l = l.strip()
        if not len(l): continue
        if not(l.startswith('d') or l.startswith('f')): continue
        contents.append(_findline_to_inode(l, server))
    return contents
Exemple #6
0
def listdir(directory, stat=False):
    server, path = _split_remote(directory)
    cmd = [ 'ssh', server, 'test -d {0} && ls {1} {0}'.format(path, '-l' if stat else '') ]
    output = run_command(cmd)
    contents = []
    for l in output:
        l = l.strip()
        if l.startswith('total '): continue
        if l.startswith('Warning'): continue
        if not len(l): continue
        if stat:
            if not(l.startswith('d') or l.startswith('-')): continue
            contents.append(_lsstatline_to_inode(l, server, path))
        else:
            contents.append(server + ':' + osp.join(path, l))
    return contents
Exemple #7
0
def mkdir(path):
    server, lpath = _split_remote(path)
    cmd = [ 'ssh', server, 'mkdir -p {0}'.format(lpath) ]
    run_command(cmd)
Exemple #8
0
def rm(path, recursive=False):
    server, path = _split_remote(directory)
    cmd = [ 'ssh', server, 'rm {1} {0}'.format(path, '-rf' if recursive else '') ]
    run_command(cmd)