idmtools.assets.asset module¶
idmtools asset class definition.
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
- class idmtools.assets.asset.Asset(absolute_path: ~typing.Optional[str] = None, relative_path: ~typing.Optional[str] = <property object>, filename: ~typing.Optional[str] = <property object>, content: ~dataclasses.InitVar = <property object>, persisted: bool = False, handler: ~typing.Callable = <class 'str'>, download_generator_hook: ~typing.Optional[~typing.Callable] = None, checksum: ~dataclasses.InitVar = <property object>)¶
Bases:
object
A class representing an asset. An asset can either be related to a physical asset present on the computer or directly specified by a filename and content.
- absolute_path: Optional[str] = None¶
The absolute path of the asset. Optional if filename and content are given.
- property checksum¶
Checksum of asset. Only required for existing assets
- property extension: str¶
Returns extension of asset.
- Returns:
Extension
Notes
This does not preserve the case of the extension in the filename. Extensions will always be returned in lowercase.
- property filename¶
Name of the file. Optional if absolute_path is given.
- property relative_path¶
The relative path (compared to the simulation root folder).
- property bytes¶
Bytes is the content as bytes.
- Returns:
None
- property length¶
Get length of item.
- Returns:
Length of the content
- property content¶
The content of the file. Optional if absolute_path is given.
- deep_equals(other: Asset) bool ¶
Performs a deep comparison of assets, including contents.
- Parameters:
other – Other asset to compare
- Returns:
True if filename, relative path, and contents are equal, otherwise false
- download_generator() Generator[bytearray, None, None] ¶
A Download Generator that returns chunks of bytes from the file.
- Returns:
Generator of bytearray
- Raises:
ValueError - When there is not a download generator hook defined –
Notes
TODO - Add a custom error with doclink.
- __init__(absolute_path: ~typing.Optional[str] = None, relative_path: ~typing.Optional[str] = <property object>, filename: ~typing.Optional[str] = <property object>, content: ~dataclasses.InitVar = <property object>, persisted: bool = False, handler: ~typing.Callable = <class 'str'>, download_generator_hook: ~typing.Optional[~typing.Callable] = None, checksum: ~dataclasses.InitVar = <property object>) None ¶
- download_stream() BytesIO ¶
Get a bytes IO stream of the asset.
- Returns:
BytesIO of the Asset
- download_to_path(dest: str, force: bool = False)¶
Download an asset to path. This requires loadings the object through the platform.
- Parameters:
dest – Path to write to. If it is a directory, the asset filename will be added to it
force – Force download even if file exists
- Returns:
None