idmtools.assets.asset_collection module¶
-
class
idmtools.assets.asset_collection.
AssetCollection
(assets: Union[List[TAsset], AssetCollection] = None, tags=None)¶ Bases:
idmtools.core.interfaces.ientity.IEntity
A class that represents a collection of assets.
- Parameters
assets – An optional list of assets to create the collection with.
-
item_type
: idmtools.core.enums.ItemType = 5¶
-
assets
: List[idmtools.assets.asset.Asset] = None¶
-
classmethod
from_id
(item_id: Union[str, uuid.UUID], platform: IPlatform = None, as_copy: bool = False, **kwargs) → AssetCollection¶ Loads a AssetCollection from id
- Parameters
item_id – Asset Collection ID
platform – Platform Ojbect
as_copy – Should you load the object as a copy. When True, the contents of AC are copied, but not the id. Useful when editing ACs
**kwargs –
- Returns
AssetCollection
-
classmethod
from_directory
(assets_directory: str, recursive: bool = True, flatten: bool = False, filters: Optional[List[Union[Callable[[TAsset], bool], Callable]]] = None, filters_mode: idmtools.core.enums.FilterMode = <FilterMode.OR: 1>, relative_path: str = None) → TAssetCollection¶ Fill up an
AssetCollection
from the specified directory. Seeassets_from_directory()
for arguments.- Returns
A created
AssetCollection
object.
-
static
assets_from_directory
(assets_directory: str, recursive: bool = True, flatten: bool = False, filters: Optional[List[Union[Callable[[TAsset], bool], Callable]]] = None, filters_mode: idmtools.core.enums.FilterMode = <FilterMode.OR: 1>, forced_relative_path: str = None) → List[idmtools.assets.asset.Asset]¶ Create assets for files in a given directory.
- Parameters
assets_directory – The root directory of the assets.
recursive – True to recursively traverse the subdirectory.
flatten – Put all the files in root regardless of whether they were in a subdirectory or not.
filters – A list of filters to apply to the assets. The filters are functions taking an
Asset
as argument and returning true or false. True adds the asset to the collection; False filters it out. Seeasset_filters()
.filters_mode – When given multiple filters, either OR or AND the results.
forced_relative_path – Prefix a relative path to the path created from the root directory.
Examples
For relative_path, given the following folder structure root/a/1,txt root/b.txt and relative_path=”test”. Will return assets with relative path: test/a/1,txt and test/b.txt
Given the previous example, if flatten is also set to True, the following relative_path will be set: /1.txt and /b.txt
- Returns
A list of assets.
-
copy
() → idmtools.assets.asset_collection.AssetCollection¶ Copy our Asset Collection, removing ID and tags
- Returns
New AssetCollection containing Assets from other AssetCollection
-
add_directory
(assets_directory: str, recursive: bool = True, flatten: bool = False, filters: Optional[List[Union[Callable[[TAsset], bool], Callable]]] = None, filters_mode: idmtools.core.enums.FilterMode = <FilterMode.OR: 1>, relative_path: str = None)¶ Retrieve assets from the specified directory and add them to the collection. See
assets_from_directory()
for arguments.
-
is_editable
(error=False) → bool¶ Checks whether Item is editable
- Parameters
error – Throw error is not
- Returns
True if editable, False otherwise.
-
add_asset
(asset: Union[idmtools.assets.asset.Asset, str], fail_on_duplicate: bool = True, **kwargs)¶ Add an asset to the collection.
- Parameters
asset – A string or an
Asset
object to add. If a string, the string will be used as the absolute_path and any kwargs will be passed to the Asset constructorfail_on_duplicate – Raise a DuplicateAssetError if an asset is duplicated. If not, simply replace it.
**kwargs – Arguments to pass to Asset constructor when asset is a string
-
add_assets
(assets: Union[List[TAsset], AssetCollection], fail_on_duplicate: bool = True)¶ Add assets to a collection
- Parameters
assets – An list of assets as either list or a collection
fail_on_duplicate – Raise a DuplicateAssetError if an asset is duplicated. If not, simply replace it.
Returns:
-
add_or_replace_asset
(asset: idmtools.assets.asset.Asset)¶ Add or replaces an asset in a collection
- Parameters
asset – Asset to add or replace
- Returns
None.
-
get_one
(**kwargs)¶ Get an asset out of the collection based on the filers passed.
Examples:
>>> a = AssetCollection() >>> a.get_one(filename="filename.txt")
- Parameters
**kwargs – keyword argument representing the filters.
- Returns
None or Asset if found.
-
delete
(**kwargs) → NoReturn¶ Delete an asset based on keywords attributes
- Parameters
**kwargs – Filter for the asset to delete.
-
remove
(**kwargs) → NoReturn¶ Remove an asset from the AssetCollection based on keywords attributes
- Parameters
**kwargs – Filter for the asset to remove.
-
pop
(**kwargs) → idmtools.assets.asset.Asset¶ Get and delete an asset based on keywords.
- Parameters
**kwargs – Filter for the asset to pop.
-
extend
(assets: List[idmtools.assets.asset.Asset], fail_on_duplicate: bool = True) → NoReturn¶ Extend the collection with new assets :param assets: Which assets to add :param fail_on_duplicate: Fail if duplicated asset is included.
-
clear
()¶
-
set_all_persisted
()¶
-
property
count
¶
-
property
uid
¶
-
has_asset
(absolute_path: str = None, filename: str = None) → bool¶ Search for asset by absolute_path or by filename
- Parameters
absolute_path – Absolute path of source file
filename – Destination filename
- Returns
True if asset exists, False otherwise
-
find_index_of_asset
(absolute_path: str = None, filename: str = None) → Optional[int]¶ Finds the index of asset by path or filename
- Parameters
absolute_path – Path to search
filename – Filename to search
- Returns
Index number if found. None if not found.
-
pre_creation
() → None¶ Called before the actual creation of the entity.
-
post_creation
() → None¶ Called after the actual creation of the entity.