COMPS.Data.AssetCollection module

class COMPS.Data.AssetCollection.AssetCollection[source]

Bases: TaggableEntity, RelatableEntity, SerializableEntity

Represents a collection of Assets.

Once saved, an AssetCollection is immutable, other than modifying tags. It contains various properties accessible by getters:

  • id

  • date_created

It also contains “child objects” (which must be specifically requested for retrieval using the QueryCriteria.select_children() method of QueryCriteria):

  • tags

  • assets

property id
property date_created
property tags
property assets
classmethod get(id=None, query_criteria=None)[source]

Retrieve one or more AssetCollections.

Parameters:
  • id – The id (str or UUID) of the AssetCollection to retrieve

  • query_criteria – A QueryCriteria object specifying basic property filters and tag-filters to apply to the set of AssetCollections returned, as well as which properties and child-objects to fill for the returned AssetCollections

Returns:

An AssetCollection or list of AssetCollections (depending on whether ‘id’ was specified) with basic properties and child-objects assigned as specified by ‘query_criteria’

refresh(query_criteria=None)[source]

Update properties of an existing AssetCollection from the server.

Since AssetCollections are mostly immutable, this is usually to retrieve/update fields or child-objects that weren’t retrieved initially (e.g. assets).

Parameters:

query_criteria – A QueryCriteria object specifying which properties and child-objects to refresh on the AssetCollection

save(return_missing_files=False, upload_files_callback=<function AssetCollection.<lambda>>)[source]

Save a single AssetCollection. An id is automatically assigned upon successful save.

When the AssetCollection contains a large number or large total size of new assets that need to be uploaded, this may be done in multiple “chunks”. This allows saving of arbitrarily-large AssetCollections while avoiding potential timeouts due to long processing time on the server.

Parameters:
  • return_missing_files – A boolean that determines the behavior when the AssetCollection being saved contains an AssetCollectionFile to be saved by md5 checksum (i.e. without uploading the data) that is not yet in COMPS. If true, when there are such files, return an array of UUIDs representing the md5 checksums of the missing files. If false, raise an error when there are any such files.

  • upload_files_callback – Callback to call whenever a batch of assets completes uploading. Default behavior is to print a single ‘.’ to the console. If the callback supplied takes 1 argument, the number of assets saved so far will be passed when it is called.

add_asset(assetcollectionfile, file_path=None, data=None, upload_callback=<function AssetCollection.<lambda>>)[source]

Add an AssetCollectionFile to an AssetCollection.

The contents of the file to add can be specified either by providing a path to the file or by providing the actual data as a byte-array. Alternately, if the file/data is already in COMPS, you can skip uploading it again and just provide an AssetCollectionFile that contains the md5 checksum of the data.

If the asset exceeds AssetManager.large_asset_upload_threshold bytes in size, the asset will be uploaded immediately, separately from the saving of the main AssetCollection. This allows saving of arbitrarily-large assets while avoiding potential timeouts or having to start from scratch in case the upload is interrupted by network issues.

NOTE: this can only be called for not-yet-saved AssetCollections, since AssetCollections are immutable once saved, other than modifying tags.

NOTE: providing both file/data and an md5 is considered invalid, as providing the md5 implies the caller knows the file/data is already in COMPS and doesn’t need to be uploaded again.

Parameters:
  • assetcollectionfile – An AssetCollectionFile containing the metadata for the file to add.

  • file_path – The path to the file to add.

  • data – The actual bytes of data to add.

  • upload_callback – Callback to call whenever a large asset upload completes saving of a chunk of the asset. Default behavior is to print a single ‘.’ to the console. If the callback supplied takes 1 argument, the number of bytes saved so far will be passed when it is called.

retrieve_as_zip()[source]

Retrieve assets associated with this AssetCollection as a single zip-file.

Returns:

returns a single byte-array of a zip-file.

static static_retrieve_as_zip(ac_id)[source]