Beispiel #1
0
def get_file_remote(key, session=None):
    cache = LocalPath(CACHE)
    cache.mkdir()
    local_path = cache / (key + '.tar.gz')
    if not local_path.exists():
        if not session:
            with SshMachine(FS) as rem:
                path = rem.path(DIR) / (key + '.tar.gz')
                assert path.exists()
                plumbum.path.utils.copy(path, local_path)
                assert local_path.exists()
        else:
            rem = session
            path = rem.path(DIR) / (key + '.tar.gz')
            assert path.exists()
            plumbum.path.utils.copy(path, local_path)
            assert local_path.exists()

    fileobj = open(str(local_path))
    return tarfile.open(fileobj=fileobj)