IStorageScope#
- class ansys.bdm.api.istorage_scope.IStorageScope#
Bases:
IReadStorageScope,ProtocolRepresents access to a Blob Data Management system. Allows consumers to produce and consume
EntityHandleinstances.This is the synchronous version of the
IAsyncStorageScopeinterface.On dispose, files within the
storage_root()that have not been passed tostore()will be deleted.
Overview#
Create an |
|
Fully reads a passed in stream and returns a handle for the given content. |
|
Create an |
|
A local filesystem directory that can be used to stage files. |
|
Delete the entities referenced by the handle. |
|
Create a recursive nested dictionary of EntityHandles from a directory. |
The set of |
|
Return an object with an asynchronous interface to the same scope. |
Track the set of files that are stored centrally. |
Import detail#
from ansys.bdm.api.istorage_scope import IStorageScope
Property detail#
- property IStorageScope.stored_entities: list[ansys.bdm.api.entity_handle.EntityHandle]#
The set of
EntityHandleinstances that have been stored via this scope.
- property IStorageScope.asynchronous: ansys.bdm.api.iasync_storage_scope.IAsyncStorageScope#
Return an object with an asynchronous interface to the same scope.
Method detail#
- IStorageScope.__enter__() IStorageScope#
Track the set of files that are stored centrally.
- IStorageScope.store(from_: PathLike[str], mime_type: str | None = None, encoding: str | None = None) ansys.bdm.api.entity_handle.EntityHandle#
Create an
EntityHandlefrom a file on disk.Many blob handler implementations will try to optimize performance and the file contents may not be immediately read from disk. To avoid class 3 type errors, the file MUST NOT be externally modified after calling this method.
- Parameters:
- from_: PathLike[str]
The local file on disk which contains the contents for the generated
EntityHandle- mime_type: Optional[str]
Mime type of this file, if known. If None is passed in, the IAsyncStorageScope SHOULD use file extension to determine the mime type.
- encoding: Optional[str]
The Internet Assigned Numbers Authority (IANA) registered encoding name used for textual data. This MAY be None if not known and SHOULD NOT be set for binary mime types.
- Returns:
- An
EntityHandlethat rerpesents the contents of the read file at the moment - this method is invoked
- An
- IStorageScope.store_stream(from_: io.RawIOBase | io.BufferedIOBase | bytes, relative_location: pathlib.Path | None = None, mime_type: str | None = None, encoding: str | None = None) ansys.bdm.api.entity_handle.EntityHandle#
Fully reads a passed in stream and returns a handle for the given content.
- Parameters:
- from_Union[RawIOBase, BufferedIOBase, bytes]
The stream or in-memory bytes from which the new entity will be created
- relative_locationOptional[Path]
The nominal relative path of the entity. The path is relative to the storage_root of the scope. No data is expected at this location. The filename from this path will be used as the original name of the entity. If this parameter is not set then the implementation will generate a unique location.
- mime_type: Optional[str]
Mime type of this file, if known. If None is passed in, the IAsyncStorageScope SHOULD use file extension to determine the mime type.
- encoding: Optional[str]
The Internet Assigned Numbers Authority (IANA) registered encoding name used for textual data. This MAY be None if not known and SHOULD NOT be set for binary mime types.
- Returns:
- EntityHandle
The
EntityHandlethat represents the passed in data.
- IStorageScope.begin_store(relative_location: pathlib.Path | None = None, mime_type: str | None = None, encoding: str | None = None) ansys.bdm.api.ientity_writer.IEntityWriter#
Create an
IEntityWriterby writing to a stream object.- Parameters:
- relative_locationOptional[Path]
The nominal relative path of the entity. The path is relative to the storage_root of the scope. No data is expected at this location. The filename from this path will be used as the original name of the entity. If this parameter is not set then the implementation will generate a unique location.
- mime_type: Optional[str]
Mime type of this file, if known. If None is passed in, the IAsyncStorageScope SHOULD use file extension to determine the mime type.
- encoding: Optional[str]
The Internet Assigned Numbers Authority (IANA) registered encoding name used for textual data. This MAY be None if not known and SHOULD NOT be set for binary mime types.
- Returns:
- IEntityWriter
An object which allows you to write to a stream and retrieve the handle.
- IStorageScope.get_storage_root() pathlib.Path#
A local filesystem directory that can be used to stage files.
Since this folder is managed by the BDM implementation, there may be performance benefits to storing files here.
This directory usually is lazy instantiated on the first call to this function.
- IStorageScope.destroy(*entities: ansys.bdm.api.entity_handle.EntityHandle) None#
Delete the entities referenced by the handle.
As
EntityHandleinstances are intended to be simple immutable structures that can be passed across process and service boundaries, their lifespan must be managed by an external system. This call allows the resources associated with a BlobHandle to be removed.- Parameters:
- *entities: EntityHandle
The entities to delete
- IStorageScope.store_to_dictionary(root: PathLike[str], glob: str | None = None) ansys.bdm.api.recursive_dictionary.RecursiveDictionaryOfEntityHandles#
Create a recursive nested dictionary of EntityHandles from a directory.
This method creates a recursive nested dictionary containing EntityHandle objects for files and nested dictionaries for directories. If glob is None, all files at or within root are included in the result.
- Parameters:
- rootPathLike[str]
The root directory to store to a nested dictionary.
- globstr | None, optional
A glob pattern to filter which files and directories to include in the result. Behaves identically to Path.rglob() and is interpreted as relative to root. Default is None.
- Returns:
- RecursiveDictionaryOfEntityHandles
A recursive nested dictionary of EntityHandle objects.
- Raises:
- FileNotFoundError
If root does not exist.
- NotADirectoryError
If root is a file.
- NotFoundInLocalStorageRootError
If root is not within the storage root of storage scope.