fs_irods.iRODSFS
Attributes
Classes
iRODS PyFilesystem2 implementation. |
Functions
|
Function to close open handles to file systems upon cleanup. |
Module Contents
- class fs_irods.iRODSFS.iRODSFS(session: irods.session.iRODSSession, root: str | None = None)[source]
Bases:
fs.base.FSiRODS PyFilesystem2 implementation.
The filesystem needs to be connected to an iRODS server via a sesseion, using valid login information.
- getinfo(path: str, namespaces: list | None = None) fs.info.Info[source]
Get information about a resource on the filesystem.
- Parameters:
- Returns:
- An Info object containing information about the
resource.
- Return type:
Info
- Raises:
ResourceNotFound – If the path does not exist.
- makedir(path: str, permissions: fs.permissions.Permissions | None = None, recreate: bool = False)[source]
Make a directory on the filesystem.
- Parameters:
path (str) – A path to a directory on the filesystem.
permissions (Permissions, optional) – A Permissions instance, or None to use default permissions. Defaults to None.
recreate (bool, optional) – If False (the default) raise an error if the directory already exists, if True do not raise an error. Defaults to False.
- Raises:
DirectoryExists – If the directory already exists and recreate is False.
ResourceNotFound – If the path does not exist.
- open(path: str, mode: str = 'r', buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str = '', **options)[source]
Open a file.
Stores weak references to open file handles that maintain a hard reference to the iRODSFS object. In this way, the iRODSFS can only be destructed once these file handles are gone.
- Parameters:
path (str) – A path to a file on the filesystem.
mode (str) – Mode to open the file object with (defaults to r).
buffering (int) – Buffering policy (-1 to use default buffering, 0 to disable buffering, 1 to select line buffering, of any positive integer to indicate a buffer size).
encoding (str) – Encoding for text files (defaults to
utf-8)errors (str, optional) – What to do with unicode decode errors (see codecs module for more information).
newline (str) – Newline parameter.
**options – keyword arguments for any additional information required by the filesystem (if any).
- Returns:
a file-like object.
- Return type:
- Raises:
fs.errors.FileExpected – If the path is not a file.
fs.errors.FileExists – If the file exists, and exclusive mode is specified (
xin the mode).fs.errors.ResourceNotFound – If the path does not exist.
- openbin(path: str, mode: str = 'r', buffering: int = -1, **options) io.BufferedRandom[source]
Open a binary file-like object on the filesystem.
- Parameters:
path (str) – A path to a file on the filesystem.
mode (str, optional) – The mode to open the file in, see the built-in open() function for details. Defaults to “r”.
buffering (int, optional) – The buffer size to use for the file, see the built-in open() function for details. Defaults to -1.
**options – Additional options to pass to the open() function.
- Returns:
A file-like object representing the file.
- Return type:
IO
- Raises:
ResourceNotFound – If the path does not exist and mode does not imply creating the file, or if any ancestor of path does not exist.
FileExpected – If the path is not a file.
FileExists – If the path exists, and exclusive mode is specified (x in the mode).
- remove(path: str)[source]
Remove a file from the filesystem.
- Parameters:
path (str) – A path to a file on the filesystem.
- Raises:
ResourceNotFound – If the path does not exist.
FileExpected – If the path is not a file.
- _check_isfile(path: str)[source]
Check if a path points to a file and raise an FileExpected error if not.
- Parameters:
path (str) – A path to a file on the filesystem.
- Raises:
ResourceNotFound – If the path does not exist.
FileExpected – If the path is not a file.
- removedir(path: str)[source]
Remove a directory from the filesystem.
- Parameters:
path (str) – A path to a directory on the filesystem.
- Raises:
ResourceNotFound – If the path does not exist.
DirectoryExpected – If the path is not a directory.
RemoveRootError – If the path is the root directory.
DirectoryNotEmpty – If the directory is not empty.
- removetree(path: str)[source]
Recursively remove a directory and all its contents.
This method is similar to removedir, but will remove the contents of the directory if it is not empty.
- Parameters:
path (str) – A path to a directory on the filesystem.
- Raises:
ResourceNotFound – If the path does not exist.
DirectoryExpected – If the path is not a directory.
- _check_isdir(path: str)[source]
Check if a path is a directory.
- Parameters:
path (str) – A path to a resource on the filesystem.
- Raises:
ResourceNotFound – If the path does not exist.
DirectoryExpected – If the path is not a directory.
- setinfo(path: str, info: dict) None[source]
Set metadata for a file or directory.
- Parameters:
- Raises:
ResourceNotFound – If the path does not exist.
ValueError – If field values are invalid.
- _validate_and_format_timestamp(value, field_name: str) int[source]
Validate that value can be parsed as a non-negative int timestamp.
- Parameters:
- Returns:
The integer timestamp.
- Return type:
- Raises:
ValueError – If value is not an integer or is negative.
- _check_exists(path: str)[source]
Check if a resource exists.
- Parameters:
path (str) – A path to a resource on the filesystem.
- Raises:
ResourceNotFound – If the path does not exist.
- create(path: str)[source]
Create a file on the filesystem.
- Parameters:
path (str) – A path to a file on the filesystem.
- Raises:
ResourceNotFound – If any ancestor of path does not exist.
FileExists – If the path exists.
- _check_points_into_collection(path: str)[source]
Check if a path points to a location inside a collection.
- Parameters:
path (str) – Path to check.
- Raises:
ResourceNotFound – If the path does not point to a location inside a collection.
- points_into_collection(path: str) bool[source]
Return true if the path is located inside a collection, aka the parent is a collection.
- move(src_path: str, dst_path: str, overwrite: bool = False, preserve_time: bool = False) None[source]
Move a file to the specified location.
- Parameters:
src_path (str) – Path to the current location of the file
dst_path (str) – Path to the target location of the file
overwrite (bool, optional) – Set to True to overwrite an existing destination file. Defaults to False.
preserve_time (bool, optional) – Set to True to preserve the original modification time. Defaults to False.
- Raises:
ResourceNotFound – If the source path does not exist, or if a parent directory of dst_path does not exist.
FileExpected – If the source path is not a file.
DestinationExists – If destination path exists and overwrite is False.
- _preserve_modified_time(src_path: str, dst_path: str) None[source]
Copy the modified time field from src to dst if present.
- movedir(src_path: str, dst_path: str, overwrite: bool = False, preserve_time: bool = False) None[source]
Move a directory to the specified location.
- Parameters:
src_path (str) – Path to the current location of the directory
dst_path (str) – Path to the target location of the directory
overwrite (bool, optional) – Set to True to overwrite an existing destination directory. Defaults to False.
preserve_time (bool, optional) – Set to True to preserve the original modification time. Defaults to False.
- Raises:
ResourceNotFound – If the source path does not exist.
DirectoryExpected – If the source path is not a directory.
DestinationExists – If destination path exists and overwrite is False.
- _init_directory_tree_metadata(src_path: str) dict[source]
Recursively collect modification time metadata for all files and directories in a directory tree.
- _collect_entry_metadata(path: str, rel: str, entry) dict[source]
Collect metadata for a file or directory entry.
- _apply_directory_tree_metadata(dst_path: str, metadata: dict) None[source]
Apply collected metadata to a directory tree at the destination.
- copy(src_path: str, dst_path: str, overwrite: bool = False, preserve_time: bool = False)[source]
Copy a file from one position to another.
- Parameters:
- Raises:
DestinationExists – If
dst_pathexists andoverwriteis False.ResourceNotFound – If a parent directory of
dst_pathdoes not exist.FileExpected – If
src_pathis not a file.
- copydir(src_path: str, dst_path: str, create: bool = False, preserve_time: bool = False)[source]
Copy the contents of the folder src_path to dst_path.
- Parameters:
- Raises:
ResourceNotFound – If the
dst_pathdoes not exist, andcreateis not True.DirectoryExpected – If
src_pathis not a directory.
- upload(path: str, file: io.IOBase | str, chunk_size: int | None = None, **options)[source]
Set a file to the contents of a binary file object.
This method copies bytes from an open binary file to a file on the filesystem. If the destination exists, it will first be truncated.
- Parameters:
path (str) – A path on the filesystem.
file (io.IOBase or str) – a file object open for reading in binary mode or a path to a local file to upload.
chunk_size (int, optional) – Number of bytes to read at a time, if a simple copy is used, or None to use sensible default.
**options – Implementation specific options required to open the source file.
- Raises:
ResourceNotFound – If a parent directory of
pathdoes not exist.
Note that the file object
filewill not be closed by this method. Take care to close it after this method completes (ideally with a context manager).Example
>>> with open('~/movies/starwars.mov', 'rb') as read_file: ... my_fs.upload('starwars.mov', read_file)
- download(path: str, file: io.IOBase | str, chunk_size=None, **options)[source]
Copy a file from the filesystem to a file-like object.
This may be more efficient that opening and copying files manually if the filesystem supplies an optimized method.
Note that the file object
filewill not be closed by this method. Take care to close it after this method completes (ideally with a context manager).- Parameters:
path (str) – Path to a resource.
file (file-like) – A file-like object open for writing in binary mode.
chunk_size (int, optional) – Number of bytes to read at a time, if a simple copy is used, or None to use sensible default.
**options – Implementation specific options required to open the source file.
Example
>>> with open('starwars.mov', 'wb') as write_file: ... my_fs.download('/Videos/starwars.mov', write_file)
- Raises:
ResourceNotFound – if
pathdoes not exist.