anod.store.component¶
Handling of Store components.
Module Contents¶
Classes¶
A Store component. |
Attributes¶
- anod.store.component.ComponentType¶
- anod.store.component.logger¶
- class anod.store.component.Component(build_id: str, name: str, platform: str, version: str, specname: str | None = None, files: list[e3.anod.store.file.File] | None = None, sources: list[e3.anod.store.file.File] | None = None, readme: e3.anod.store.file.File | None = None, attachments: dict[str, e3.anod.store.file.File] | list[ComponentAttachmentDict] | None = None, releases: list[str] | None = None, is_valid: bool = True, is_published: bool = False, component_id: str | None = None, creation_date: datetime.datetime | None = None, build_info: e3.anod.store.buildinfo.BuildInfo | None = None, store: e3.anod.store.interface.StoreReadInterface | e3.anod.store.interface.StoreRWInterface | None = None, metadata: dict[str, object] | None = None)¶
A Store component.
A component is an entity that regroups binaries, sources and additional metadata.
- Variables:
build_id (str) – build id
name (str) – component name
platform (str) – platform
version (str) – version
specname (str | None) – the name of the spec that created the component
files (list[anod.store.file.File] | None) – list of binary files
sources (list[anod.store.file.File] | None) – list of sources
readme (anod.store.file.File | None) – readme file if present
releases (list[str] | None) – list of releases
is_valid (bool) – True if the component is valid
is_published (bool) – True if published
component_id (str | None) – ID of the component if defined
creation_date (datetime.datetime | None) – component creation date
build_info (BuildInfo | None) – build info
store (StoreReadInterface | StoreRWInterface | None | None) – The store instance defined for this component
- __hash__¶
- set_metadata_statement(name: str, data: e3.dsse.DSSE) None¶
Set additional metadata statement.
- Parameters:
name – Statement name
data – The Dead Simple Signature envelope of the data associated with name.
- get_metadata_statement(name: str) e3.dsse.DSSE | None¶
Get metadata statement.
- Parameters:
name – statement name
- Returns:
a DSSE envelope
- add_attachment(key: str, file: e3.anod.store.file.File, overwrite_existing: bool = False) str | None¶
Add a file in this component’s attachments.
Add given file to this component’s attachments. A key made of key,*file.filename* is returned if the file was actually attached.
If
key,file.filenameis already in the list of attachments, and overwrite_existing is False, None is returned.- Parameters:
key – The key defining the type of attachment. For instance,
"acats". A coma and the file’sfilenameis appended to this key to populate the attachment’s dictionary.file – The file to be appended to this component’s attachments.
overwrite_existing – If True, the given file is added to this component’s attachments, even if a file with the same key and file.filename is already attached.
- Returns:
The key of the attached file, or None if the file could not be attached.
- get_attachments(key: str | None = None) dict[str, e3.anod.store.file.File]¶
Get the list of attachments matching key.
If an attachment key starts with
<key>,, it is added to the returned list.If key is set to None, all elements are returned.
- Parameters:
key – The attachment key to match. If set to None, all attachments are returned.
- Returns:
A list of dictionaries. Each dictionary is simply made of the matching key and the attached file.
- classmethod metadata_path(dest_dir: str, name: str) str¶
Return path to file containing component metadata.
- Parameters:
dest_dir – directory in which the metadata file can be found
name – file basename
- Returns:
a path to the metadata file
- remove_attachment(key: str | None = None) bool¶
Remove an attachment by key.
To remove all “spdx” attachments (for instance), use component.remove_attachment(“spdx”).
- Parameters:
key – The attachment key to match. If None, all attachments are removed.
- Returns:
True if an attachment is actually removed, False if no attachment matching key could be removed.
- save_to_meta_file(dest_dir: str, name: str | None = None) None¶
Dump as json file component information.
- Parameters:
dest_dir – directory in which the metadata file should be saved
name – file basename
- submit_attachment(key: str, file: e3.anod.store.file.File) ComponentDict¶
Submit an attachment to a store component.
Add an attachment to an existing component, upload the file to Store, and update the list of attachments for that component.
- Parameters:
key – The type of attachment (“spdx” for instance).
file – The file to be uploaded and attached to this component.
- Returns:
The updated component.
- Raises:
e3.anod.store.interface.StoreError – If the current store is not a writable instance
e3.anod.store.interface.StoreError – If submitting file did not return a valid ID
FileNotFoundError – If file has no valid download_as field (meaning the file does not exist on the file system)
ValueError – If this component is invalid (no valid ID)
ValueError – If file has no resource ID
ValueError – If the file could not be added to the attachments
- classmethod load_from_meta_file(dest_dir: str, name: str, store: e3.anod.store.interface.StoreReadInterface | None = None, ignore_errors: Literal[False] = False) ComponentType¶
- classmethod load_from_meta_file(dest_dir: str, name: str, store: e3.anod.store.interface.StoreReadInterface | None = None, ignore_errors: Literal[True] = True) ComponentType | None
Load components from a metadata file.
- Parameters:
dest_dir – directory in which the metadata is located
name – file basename
store – a store instance to bind to the returned object
ignore_errors – if True, in case of errors return None. Otherwise, StoreError is raised.
- Returns:
a component instance
- as_dict() ComponentDict¶
Return a dictionary representation of self.
Feeding to this class’ “load” method the value returned by this method creates a new Component value that is equal to self.
- Returns:
The dictionary representation of self.
- Return type:
dict
- classmethod load(data: ComponentDict, store: e3.anod.store.interface.StoreReadInterface | e3.anod.store.interface.StoreRWInterface | None = None) typing_extensions.Self¶
Create a Component from the result of a Store request.
- Parameters:
data – The dictionary returned by Store.
store – a Store instance
- classmethod latest(store: e3.anod.store.interface.StoreReadInterface | e3.anod.store.interface.StoreRWInterface, setup: str, date: str | None = None, platform: str = 'all', component: str = 'all', specname: str | None = None, build_id: str = 'all') list[typing_extensions.Self]¶
Get a list of latest components.
- Parameters:
store – a store instance
setup – setup name
date – a build date. If not None then this means that only components from a given build date are considered.
platform – a platform name. If set to
`all`then latest component for each platform is returned.component – a component name. If set to
`all`then latest component for each component name is returned.specname – the name of the spec that produced the component. If not None then this means that only components generated from the given specname are considered.
build_id – the build id to use or “all”.
- Returns:
a list of Components
- download(dest_dir: str | None, as_name: str | None = None, unpack_dir: str | None = None, save_metadata: bool = True, remove_root_dir: e3.archive.RemoveRootDirType = True, unpack_cmd: collections.abc.Callable[Ellipsis, None] | None = None, delete: bool = True, ignore: list[str] | None = None, tmp_dir_root: str | None = None) bool | None¶
Download the binary file associated with a component.
- Parameters:
dest_dir – directory in which the archive is kept. If None then the archive will be downloaded in a temporary location and deleted before the function returns. Having both unpack_dir and dest_dir set to None will result in a dummy operation.
as_name – if set to None then the resulting filename is the binary ‘name’ + an extension. If not None as_name is used instead. The extension used is the extension of the filename attribute. If the name attribute or as_name already have the same extension as filename then the extension won’t be repeated twice.
unpack_dir – if not None a call to unpack_archive is done with destination set to unpack_dir.
save_metadata – if True save a metadata file along with the downloaded file. Note that the option has no effect if dest_dir is set to None
remove_root_dir – see e3.archive.unpack_archive. Relevant only if unpack_dir is not None. Default is True
unpack_cmd – see e3.archive.unpack_archive. Relevant only if unpack_dir is not None. Default is None
delete – see e3.archive.unpack_archive. Relevant only if unpack_dir is not None. Default is True
ignore – see e3.archive.unpack_archive. Relevant only if unpack_dir is not None. Default is None
tmp_dir_root – see e3.archive.unpack_archive. Relevant only when remove_root_dir is True.
- Returns:
None if there are no binary associated, True if the file has been downloaded, or False if the file was already downloaded
- push() typing_extensions.Self¶
Push the component to store, using self.store to do so.
This operation requires self.store to be a StoreRWInterface; otherwise, this method will crash.
- Raises:
AttributeError – If self.store is not a StoreRWInterface interface.
- Returns:
A newly created Component instance of the final component. The current instance is also updated accordingly.
- __update(component: Component) None¶
Update this component data.
This method is used to update the value of the current component from another.
This is especially used after a component is pushed to our store to update this component with the uploaded one, because after pushing a component, some internal values may change (for example, a component_id will be generated).
- Parameters:
component – The component object used to update the current one.
- __eq__(other: object) bool¶
Compare two component object.
- Parameters:
other – the other object to compare with the current one.
- Returns:
False if other is not a component or if other is different to the current component.
- __ne__(other: object) bool¶
Inverse of self.__eq__.
- Parameters:
other – the object to compare with
- Returns:
True if not self.__eq__(other).