IReadStorageScope#
- class ansys.bdm.api.istorage_scope.IReadStorageScope#
Bases:
ProtocolRepresents access to a read only Blob Data Management system. Allows consumers to produce and consume
EntityHandleinstances.This is the synchronous version of the
IAsyncReadStorageScopeinterface.
Overview#
Realize the data to a local filesystem if needed and returns a path to the cached or original file. |
|
Realize the data to a local filesystem by writing to a specified file. |
|
Open the EntityHandle contents for reading as a stream. |
|
Return the content of the referenced blob. |
|
Return the content of the referenced blob. |
|
Return the entities contained in this entity. |
|
Return the entity contained in this entity with a given name. |
|
Return the entity containing in this entity. |
|
Return a list of all entities within the context that are not referenced by the given live entity handles. |
|
Create a recursive directory structure containing copies of entities from source. |
Return a object with an asynchronous interface to the same scope. |
Import detail#
from ansys.bdm.api.istorage_scope import IReadStorageScope
Property detail#
- property IReadStorageScope.asynchronous: ansys.bdm.api.iasync_storage_scope.IAsyncReadStorageScope#
Return a object with an asynchronous interface to the same scope.
Method detail#
- IReadStorageScope.__enter__() IReadStorageScope#
Track the set of files that are stored centrally.
- IReadStorageScope.__exit__(__exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: types.TracebackType | None) None#
Remove all files from local storage that are not stored centrally.
- IReadStorageScope.get_cached(entity: ansys.bdm.api.entity_handle.EntityHandle) pathlib.Path#
Realize the data to a local filesystem if needed and returns a path to the cached or original file.
The
EntityHandleis intended to represent an immutable value. The file returned by this call may point to a cached or even the original file. Callers must not modify the file on disk or undefined behavior, including class 3 errors, may occur. If the caller needs to modify the file, consider usingget_copy(), or copying the file before modifying it.- Parameters:
- entity: EntityHandle
The handle to the data to realize
- Returns:
- Path
The path to the contents of the EntityHandle as realized locally. The caller MUST NOT modify the returned path.
- IReadStorageScope.get_copy(entity: ansys.bdm.api.entity_handle.EntityHandle, destination: pathlib.Path) None#
Realize the data to a local filesystem by writing to a specified file.
The caller is free to modify the written file. The caller is responsible for deleting the generated file. If the destination path is within the storage root then the copy at that location will be deleted when the storage scope context is closed.
- Parameters:
- entity: EntityHandle
The handle to the data to realize
- destination: Path
The path to the file to write
- IReadStorageScope.get_stream(entity: ansys.bdm.api.entity_handle.EntityHandle) io.RawIOBase#
Open the EntityHandle contents for reading as a stream.
The returned stream MUST NOT be writable. The returned stream MAY be seekable.
- Parameters:
- entity: EntityHandle
The handle to the data to realize
- Returns:
- RawIOBase
The stream which, when read, will return the contents of the EntityHandle.
- Raises:
- CannotGenerateStreamForDirectoryError
If the entity requested is a collection
- IReadStorageScope.get_bytes(entity: ansys.bdm.api.entity_handle.EntityHandle) bytes#
Return the content of the referenced blob.
- Parameters:
- entity: EntityHandle
The handle to the data to realize
- Returns:
- bytes
the contents of the EntityHandle.
- Raises:
- CannotGenerateStreamForDirectoryError
If the entity requested is a collection
- IReadStorageScope.get_text(entity: ansys.bdm.api.entity_handle.EntityHandle, encoding: str | None = None) str#
Return the content of the referenced blob.
- Parameters:
- entity: EntityHandle
The handle to the data to realize
- encoding: Optional[str]
The name of an encoding. When this argument is not None the bytes of
entitywill be read using that encoding.
- Returns:
- str
the contents of the EntityHandle in text form with the encoding determined in order of preference by: - the encoding argument if not None - the encoding field of the entity argument if set - the BOM of the referenced entity if it contains one; or - UTF-8
- Raises:
- CannotGenerateStreamForDirectoryError
If the entity requested is a collection
- IReadStorageScope.get_children(entity: ansys.bdm.api.entity_handle.EntityHandle) list[ansys.bdm.api.entity_handle.EntityHandle]#
Return the entities contained in this entity.
- Parameters:
- entity: EntityHandle
The entity to query
- Returns:
- List[EntityHandle]
The list of entities that are children of the provided entity
- Raises:
- NotADirectoryError
If the requested entity is not a directory
- IReadStorageScope.get_child(entity: ansys.bdm.api.entity_handle.EntityHandle, child_name: str) ansys.bdm.api.entity_handle.EntityHandle#
Return the entity contained in this entity with a given name.
- Parameters:
- entity: EntityHandle
The entity to query
- child_name: str
The child to search for
- Returns:
- EntityHandle
The
EntityHandlerequested
- Raises:
- NotADirectoryError
If the requested entity is not a directory
- EntityNotFoundInBlobStorageError
If the requested entity is not found
- IReadStorageScope.get_parent(entity: ansys.bdm.api.entity_handle.EntityHandle) ansys.bdm.api.entity_handle.EntityHandle | None#
Return the entity containing in this entity.
- Parameters:
- entity: EntityHandle
The entity to query
- Returns:
- Optional[EntityHandle]
The
EntityHandlerequested, or None if the entity is stored at the root of its scope.
- Raises:
- EntityNotFoundInBlobStorageError
If the requested entity is not found.
- IReadStorageScope.get_unreferenced_entities(context: str, live_handles: list[ansys.bdm.api.entity_handle.EntityHandle]) list[ansys.bdm.api.entity_handle.EntityHandle]#
Return a list of all entities within the context that are not referenced by the given live entity handles.
- Parameters:
- context: str
A label for storage scopes that enables them to be categorized and configured given a common system wide configuration. It defines the bounds over which methods supporting garbage collection are constrained.
- live_handles: list[EntityHandle]
A list of handles that are expected to refer to blobs.
- Returns:
- list[EntityHandle]
The list of all entities within the context that are not referenced by the given live entity handles.
- Raises:
- ValueError
If the live_handles do not belong to the provided context.
- IReadStorageScope.get_copy_from_dictionary(root: PathLike[str], source: ansys.bdm.api.recursive_dictionary.RecursiveDictionaryOfEntityHandles, glob: str | None = None) None#
Create a recursive directory structure containing copies of entities from source.
This method creates a directory structure on the file system at root containing copies of the entities in source. If glob is None, all files at or within source are copied to root. Note that file and directory names used when creating the directory structure at root are always taken from the keys in source, not from the original_name attribute of the EntityHandle objects.
- Parameters:
- rootPathLike[str]
The root directory to create the directory structure in.
- sourceRecursiveDictionaryOfEntityHandles
A recursive nested dictionary of EntityHandle objects.
- globstr | None, optional
A glob pattern to filter which files and directories to copy. Behaves identically to Path.match() and is interpreted as relative to root using the keys in source as the path components. Default is None.
- Raises:
- NotADirectoryError
If root points to an existing file.