FileSystem¶
authentication¶
- FileSystem.authentication¶
Object used for authentication, e.g. username, password tuple.
checksum()¶
- FileSystem.checksum(path)¶
MD5 checksum for file on backend.
- Parameters:
path (
str) – path to file on backend- Return type:
- Returns:
MD5 checksum
- Raises:
BackendError – if an error is raised on the backend, e.g.
pathdoes not existValueError – if
pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
close()¶
- FileSystem.close()¶
Close connection to backend.
- Raises:
BackendError – if an error is raised on the backend
copy_file()¶
- FileSystem.copy_file(src_path, dst_path, *, num_workers=1, validate=False, verbose=False)¶
Copy file on backend.
If
dst_pathexists and has a different checksum, it is overwritten. Otherwise, the operation is silently skipped.If
validateis set toTrue, a final check is performed to assert thatsrc_pathanddst_pathhave the same checksum. If it fails,dst_pathis removed and anInterruptedErroris raised.- Parameters:
- Raises:
BackendError – if an error is raised on the backend
InterruptedError – if validation fails
ValueError – if
src_pathordst_pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
create()¶
- classmethod FileSystem.create(host, repository, *, authentication=None)¶
Create repository.
Creates
repositorylocated athoston the backend.- Parameters:
- Raises:
BackendError – if an error is raised on the backend, e.g. repository exists already or cannot be created
date()¶
- FileSystem.date(path)¶
Last modification date of file on backend.
If the date cannot be determined, an empty string is returned.
- Parameters:
path (
str) – path to file on backend- Return type:
- Returns:
date in format
'yyyy-mm-dd'- Raises:
BackendError – if an error is raised on the backend, e.g.
pathdoes not existValueError – if
pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
delete()¶
- classmethod FileSystem.delete(host, repository, *, authentication=None)¶
Delete repository.
Deletes
repositorylocated athoston the backend.- Parameters:
- Raises:
BackendError – if an error is raised on the backend, e.g. repository does not exist
exists()¶
- FileSystem.exists(path, *, suppress_backend_errors=False)¶
Check if file exists on backend.
- Parameters:
- Return type:
- Returns:
Trueif file exists- Raises:
BackendError – if
suppress_backend_errorsisFalseand an error is raised on the backend, e.g. due to a connection timeoutValueError – if
pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'ValueError – if
versionis empty or does not match'[A-Za-z0-9._-]+'RuntimeError – if backend was not opened
get_archive()¶
- FileSystem.get_archive(src_path, dst_root, *, tmp_root=None, num_workers=1, validate=False, verbose=False)¶
Get archive from backend and extract.
For ZIP archives, streaming extraction is used if
stream-unzipis installed, andnum_workers=1. It extracts files during download without storing the archive locally.For uncompressed archives or archives that do not support streaming extraction, the archive is downloaded first and then extracted. In that case we recommend setting
num_workers=5for best performance.If
dst_rootdoes not exist, it is created.If
validateis set toTrue, a final check is performed to assert thatsrc_pathand the retrieved archive have the same checksum. If it fails, the extracted files are removed and anInterruptedErroris raised.- Parameters:
src_path (
str) – path to archive on backenddst_root (
str) – local destination directorytmp_root (
str) – directory under which archive is temporarily extracted. Defaults to temporary directory of system. Not used for ZIP archives whenstream-unzipis available.num_workers (
int) – number of parallel jobsvalidate (
bool) – verify archive was successfully retrieved from the backendverbose (
bool) – show debug messages
- Return type:
- Returns:
extracted files
- Raises:
BackendError – if an error is raised on the backend, e.g.
src_pathdoes not existFileNotFoundError – if
tmp_rootdoes not existInterruptedError – if validation fails
NotADirectoryError – if
dst_rootis not a directoryPermissionError – if the user lacks write permissions for
dst_pathRuntimeError – if extension of
src_pathis not supported orsrc_pathis a malformed archiveValueError – if
src_pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
get_file()¶
- FileSystem.get_file(src_path, dst_path, *, num_workers=1, validate=False, verbose=False)¶
Get file from backend.
If the folder of
dst_pathdoes not exist, it is created.If
dst_pathexists with a different checksum, it is overwritten, Otherwise, the operation is silently skipped.If
validateis set toTrue, a final check is performed to assert thatsrc_pathanddst_pathhave the same checksum. If it fails,dst_pathis removed and anInterruptedErroris raised.- Parameters:
- Return type:
- Returns:
full path to local file
- Raises:
BackendError – if an error is raised on the backend, e.g.
src_pathdoes not existInterruptedError – if validation fails
IsADirectoryError – if
dst_pathpoints to an existing folderPermissionError – if the user lacks write permissions for
dst_pathValueError – if
src_pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
host¶
- FileSystem.host¶
Host path.
join()¶
- FileSystem.join(path, *paths)¶
Join to (sub-)path on backend.
- Parameters:
path (
str) – first part of path*paths – additional parts of path
- Return type:
- Returns:
path joined by
Backend.sep- Raises:
ValueError – if
pathcontains invalid character or does not start with'/', or if joined path contains invalid character
ls()¶
- FileSystem.ls(path='/', *, pattern=None, suppress_backend_errors=False)¶
List files on backend.
Returns a sorted list of tuples with path and version. If a full path (e.g.
/sub/file.ext) is provided, all versions of the path are returned. If a sub-path (e.g./sub/) is provided, all files that start with the sub-path are returned. Whenpathis set to'/'a (possibly empty) list with all files on the backend is returned.- Parameters:
path (
str) – path or sub-path (if it ends with'/') on backendpattern (
str) – if notNone, return only files matching the pattern string, seefnmatch.fnmatch()suppress_backend_errors (
bool) – if set toTrue, silently catch errors raised on the backend and return an empty list
- Return type:
- Returns:
list of tuples (path, version)
- Raises:
BackendError – if
suppress_backend_errorsisFalseand an error is raised on the backend, e.g.pathdoes not existValueError – if
pathdoes not start with'/'or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
move_file()¶
- FileSystem.move_file(src_path, dst_path, *, num_workers=1, validate=False, verbose=False)¶
Move file on backend.
If
dst_pathexists and has a different checksum, it is overwritten. Otherwise,src_pathis removed and the operation silently skipped.If
validateis set toTrue, a final check is performed to assert thatsrc_pathanddst_pathhave the same checksum. If it fails,dst_pathis removed and anInterruptedErroris raised. To ensuresrc_pathstill exists in this case it is first copied and only removed when the check has successfully passed.- Parameters:
- Raises:
BackendError – if an error is raised on the backend
InterruptedError – if validation fails
ValueError – if
src_pathordst_pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
open()¶
- FileSystem.open()¶
Open connection to backend.
Repository must exist, use
audbackend.backend.Base.create()to create it. Finally, useaudbackend.backend.Base.close()to close the connection. Instead of explicitly callingaudbackend.backend.Base.open()andaudbackend.backend.Base.close()it is good practice to use a with statement.- Raises:
BackendError – if an error is raised on the backend, e.g.
repositorydoes not exist
opened¶
- FileSystem.opened¶
If a connection to the repository has been established.
owner()¶
- FileSystem.owner(path)¶
Owner of file on backend.
If the owner of the file cannot be determined, an empty string is returned.
- Parameters:
path (
str) – path to file on backend- Return type:
- Returns:
owner
- Raises:
BackendError – if an error is raised on the backend, e.g.
pathdoes not existValueError – if
pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
put_archive()¶
- FileSystem.put_archive(src_root, dst_path, *, files=None, tmp_root=None, validate=False, verbose=False)¶
Create archive and put on backend.
The archive type is derived from the extension of
dst_path. Seeaudeer.create_archive()for supported extensions.The operation is silently skipped, if an archive with the same checksum already exists on the backend.
If
validateis set toTrue, a final check is performed to assert that the local archive anddst_pathhave the same checksum. If it fails,dst_pathis removed and anInterruptedErroris raised.- Parameters:
src_root (
str) – local root directory where files are located. By default, all files belowsrc_rootwill be included into the archive. Usefilesto select specific filesdst_path (
str) – path to archive on backendfiles (
str|Sequence[str]) – file(s) to include into the archive. Must exist withinsrc_roottmp_root (
str) – directory under which archive is temporarily created. Defaults to temporary directory of systemvalidate (
bool) – verify archive was successfully put on the backendverbose (
bool) – show debug messages
- Raises:
BackendError – if an error is raised on the backend
FileNotFoundError – if
src_root,tmp_root, or one or morefilesdo not existInterruptedError – if validation fails
NotADirectoryError – if
src_rootis not a folderRuntimeError – if
dst_pathdoes not end withziportar.gzor a file infilesis not belowrootValueError – if
dst_pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
put_file()¶
- FileSystem.put_file(src_path, dst_path, *, validate=False, verbose=False)¶
Put file on backend.
The operation is silently skipped, if a file with the same checksum already exists on the backend.
If
validateis set toTrue, a final check is performed to assert thatsrc_pathanddst_pathhave the same checksum. If it fails,dst_pathis removed and anInterruptedErroris raised.- Parameters:
- Raises:
BackendError – if an error is raised on the backend
FileNotFoundError – if
src_pathdoes not existInterruptedError – if validation fails
IsADirectoryError – if
src_pathis a folderValueError – if
dst_pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
remove_file()¶
- FileSystem.remove_file(path)¶
Remove file from backend.
- Parameters:
path (
str) – path to file on backend- Raises:
BackendError – if an error is raised on the backend, e.g.
pathdoes not existValueError – if
pathdoes not start with'/', ends on'/', or does not match'[A-Za-z0-9/._-]+'RuntimeError – if backend was not opened
repository¶
- FileSystem.repository¶
Repository name.
sep¶
- FileSystem.sep¶
File separator on backend.
Returns: file separator
split()¶
- FileSystem.split(path)¶
Split path on backend into sub-path and basename.
- Parameters:
path (
str) – path containingBackend.sepas separator- Return type:
- Returns:
tuple containing (root, basename)
- Raises:
ValueError – if
pathdoes not start with'/'or does not match'[A-Za-z0-9/._-]+'