anod.store.interface

Store interface for Anod binary and source packages.

Module Contents

Classes

_StoreContextManager

A class to define the context manager interface needed by a Store class.

StoreReadInterface

A class that defines the Store read interface.

StoreWriteInterface

A class that defines the Store write interface.

StoreRWInterface

Combined read-write interface for store operations.

LocalStoreInterface

Interface for local store operations.

Functions

resource_id(→ str)

Given a path to a file return the resource id.

Attributes

StoreContextManagerType

anod.store.interface.StoreContextManagerType
exception anod.store.interface.StoreError(message: str | list[str], origin: str | None = None)

Bases: e3.error.E3Error

Exception raised for store operations errors.

exception anod.store.interface.StoreConnectionError(message: str | list[str], origin: str | None = None)

Bases: StoreError

Exception used to indicate a connection error with the online store.

Having this special exception allows the user to make distinction between access to the store and request errors (for example when an object cannot be found).

anod.store.interface.resource_id(path: os.PathLike[str] | str) str

Given a path to a file return the resource id.

Parameters:

path – a path to an existing path

Returns:

a resource id

class anod.store.interface._StoreContextManager

A class to define the context manager interface needed by a Store class.

abstract __enter__() StoreContextManagerType

Enter in a new context.

This method is called when used with the “with” keyword. For example:

with _StoreContextManager() as x:
    pass
Returns:

Self

abstract __exit__(*args: object) None

Exit a context.

This method is called when exiting a “with” context. For example:

with _StoreContextManager() as x:
    pass
# __exit__ is call here
abstract close() None

Close the current context.

This method is used to close a context, generally not initiated using the with keyword. See builtin.open for more example.

class anod.store.interface.StoreReadInterface

Bases: _StoreContextManager

A class that defines the Store read interface.

classmethod resource_id(path: str) str

Given a path to a file return the resource id.

Parameters:

path – a path to an existing path

Returns:

a resource id

abstract list_release_components(name: str, component: str = 'all', version: str = 'all', platform: str = 'all') list[e3.anod.store.component.ComponentDict]

List components for a given release name.

Parameters:
  • name – The release name.

  • component – A component name or ‘all’ to match all components.

  • version – A component version or all to match all version.

  • platform – A platform name or ‘all’ to match all platforms.

Returns:

a list of component description. See e3.anod.store.component.Component.load implementation for the description of the expected structure.

abstract list_components(bid: str, component: str = 'all', platform: str = 'all') list[e3.anod.store.component.ComponentDict]

List components for a given build id.

Parameters:
  • bid – a build id

  • component – a component name or ‘all’ to match all components

  • platform – a platform name or ‘all’ to match all platforms

Returns:

a list of component description. See e3.anod.store.component.Component.load implementation for the description of the expected structure.

abstract latest_components(setup: str, date: str | None = None, platform: str = 'all', component: str = 'all', specname: str | None = None, build_id: str = 'all') list[e3.anod.store.component.ComponentDict]

Get a list of latest components.

Parameters:
  • setup – the setup name

  • date – a build date or None

  • platform – a platform name or ‘all’ to match all platforms

  • component – a component name or ‘all’ to get all components

  • specname – the name of the spec that generated the component or ‘all’ to include all “generator” specs

  • build_id – a build id

Returns:

a list of component description. See e3.anod.store.file.File.load. Note that no error is raised when no component matching the criteria is found (an empty list is returned).

abstract get_build_data(bid: str) BuildDataDict

Fetch all data corresponding to a build id.

Parameters:

bid – a build id

Returns:

a dict with two keys: ‘components’ and ‘sources’. If key as a list associated. See e3.anod.store.file.File.load and e3.anod.store.component.Component.load for description of the expected structure

abstract get_build_info(bid: str) e3.anod.store.buildinfo.BuildInfoDict

Get build metadata.

Parameters:

bid – a build id

Returns:

a dict with the build metadata. See e3.anod.store.buildinfo.BuildInfo.load for description of the structure.

abstract get_build_info_list(date: str | None = 'all', setup: str | None = 'all', version: str | None = 'all', nb_days: int = 1) list[e3.anod.store.buildinfo.BuildInfoDict]

Get latest build metadata for the last nb_days days.

Parameters:
  • date – a build date to start lookup from

  • setup – a setup name

  • version – a build version or ‘all’. None has the same meaning as ‘all’

  • nb_days – maximum number of days to get build information for.

Returns:

a dict with the build metadata. See e3.anod.store.buildinfo.BuildInfo.load for description of the structure.

abstract get_latest_build_info(setup: str, date: str | None = 'all', version: str | None = 'all', ready_only: bool = True) e3.anod.store.buildinfo.BuildInfoDict

Get latest build metadata.

Parameters:
  • setup – a setup name

  • date – a build date or ‘all’. None has the same meaning as ‘all’

  • version – a build version or ‘all’. None has the same meaning as ‘all’

  • ready_only – if True discard build that are not marked ‘isready’

Returns:

a dict with the build metadata. See e3.anod.store.buildinfo.BuildInfo.load for description of the structure.

abstract get_source_info(name: str, bid: str, kind: str = 'source') e3.anod.store.file.FileDict

Get source metadata.

Important note: if the source does not exist for the required bid then the latest source with a build id anterior to the requested one will be returned for the corresponding setup.

Parameters:
  • name – The name of the source to get info for.

  • bid – a build id

  • kind – source kind. Can be currently ‘source’ or ‘thirdparty’.

Returns:

a dict representing a file structure (see e3.anod.store.file.File.load)

abstract download_resource(rid: str, path: str) str

Download a resource.

Parameters:
  • rid – the resource id

  • path – destination

Returns:

absolute path to the downloaded resource

abstract latest_thirdparty(name: str, tp_id: str = 'all', rid: str = 'all') e3.anod.store.file.FileDict | None

Get third party metadata.

Parameters:
  • name – Third party name.

  • tp_id – Third party id or ‘all’.

  • rid – Third party resource_id or ‘all’.

Returns:

a dict representing a file structure or None if the third party does not exist. (See e3.anod.store.file.File.load)

abstract bulk_query(queries: list[dict[str, Any]]) list[dict[str, Any]]

Perform a list of queries (source and components) to Store.

Each element of the queries list should conform to the following specifications:

Source queries have the following format:

{'query': 'source',
 'name':  'str'  # The name of the File to retrieve
 'kind':  'str'  # 'thirdparty' or 'source' (OPTIONAL)
 'bid':   'str'  #  NECESSARY if kind not is not 'thirdparty'}

Component queries have the following format:

{'query': 'component',
 'platform': 'str',
 'name': 'str',
 'setup': 'str',
 'date': 'str'  # OPTIONAL}

The answer is a JSON array. Each item has the following format:

{‘query’: dict # A copy of the input query

‘msg’: str # A message in case of error ‘response’: dict # A query answer (a file or component structure)}

Parameters:

queries – a list of queries

Returns:

a list of answers

class anod.store.interface.StoreWriteInterface

A class that defines the Store write interface.

abstract create_thirdparty(file_info: e3.anod.store.file.FileDict) e3.anod.store.file.FileDict

Upload a new third party.

Parameters:

file_info – a dict representing a file structure. (see e3.anod.store.file.File.load)

Returns:

a dict representing the final file structure (see e3.anod.store.file.File.load)

abstract submit_component(component_info: e3.anod.store.component.ComponentDict) e3.anod.store.component.ComponentDict

Upload a component to store.

Parameters:

component_info – a dict representing a component

Returns:

a dict representing the final component

abstract submit_file(file_info: e3.anod.store.file.FileDict) e3.anod.store.file.FileDict

Upload a new file to store.

Parameters:

file_info – a dict representing a file structure

Returns:

a dict representing the final file structure

abstract mark_build_ready(bid: str) bool

Mark a build id as ready.

The mechanism is used to synchronize source packaging with component builds startup

Parameters:

bid – a build id

Returns:

True if success

abstract create_build_id(setup: str, date: str, version: str) e3.anod.store.buildinfo.BuildInfoDict

Create a new build id.

Parameters:
  • setup – the setup name

  • date – the build date of the new build id

  • version – the version of the new build id

Returns:

a build id dict

abstract copy_build_id(bid: str, dest_setup: str) e3.anod.store.buildinfo.BuildInfoDict

Copy a build id.

Parameters:
  • bid – a build id

  • dest_setup – setup destination different from source setup

Returns:

a dict representing a build id

abstract update_file_metadata(file_info: e3.anod.store.file.FileDict) e3.anod.store.file.FileDict

Update file resource metadata.

Parameters:

file_info – a dict representing a file structure

Returns:

a dict representing the updated file

abstract add_component_attachment(component_id: str, file_id: str, name: str) None

Add an attachment to a component.

This function attach an ALREADY SUBMITTED file to a component.

Parameters:
  • component_id – the component id.

  • file_id – the id of the attachment file.

  • name – the attachment name.

class anod.store.interface.StoreRWInterface

Bases: StoreReadInterface, StoreWriteInterface

Combined read-write interface for store operations.

class anod.store.interface.LocalStoreInterface

Interface for local store operations.

abstract raw_add_build_info(build_info_data: e3.anod.store.buildinfo.BuildInfoDict) None

Add a build info to the local store.

Parameters:

build_info_data – build info data (i.e: result of BuildInfo.as_dict())

abstract add_build_info_from_store(from_store: StoreReadInterface, bid: str) None

Add a build info to the local store from another store instance.

Parameters:
  • from_store – The other store instance where the buildinfo is retrieve.

  • bid – The buildinfo ID to retrieve.

abstract raw_add_file(file_info: e3.anod.store.file.FileDict) None

Add a file to the local store.

Parameters:

file_info – a file dict (i.e: result of File.as_dict()).

abstract add_source_from_store(from_store: StoreReadInterface, name: str, bid: str | None = None, setup: str | None = None, date: str = 'all', kind: Literal[source, thirdparty] = 'source') None

Add a file info and all associated informations to the db.

The associated build id is also automatically added.

Note

If the file information is already present no call to the online store is performed.

This method doesn’t retrieve the resource pointed by the added file. Trying to download the file without calling add_resource will raise an error.

Parameters:
  • from_store – instance of an online store to query.

  • name – the source name to retrieve.

  • bid – a build id.

  • setup – a setup name.

  • date – a build date.

  • kind – kind can be either source or thirdparty.

abstract raw_add_component(component_info: e3.anod.store.component.ComponentDict) None

Add a component to the local store.

Parameters:

component_info – a Component dict (i.e: result of Component.as_dict()).

abstract add_component_from_store(from_store: StoreReadInterface, setup: str, name: str = 'all', platform: str = 'all', date: str | None = None, specname: str | None = None) None

Add a component and all associated informatios to the db.

The associated build id is also automatically added

Parameters:
  • from_store – instance of an online store to query.

  • setup – a setup name.

  • name – a component name.

  • platform – a platform name.

  • date – a build date.

  • specname – the spec name related to the component.

abstract save(filename: pathlib.Path | None = None) None

Save the local store database.

This function can does nothing and is hightly related to the LocalStore implementation.

Parameters:

filename – the file path to save the database.

abstract bulk_update_from_store(from_store: StoreReadInterface, queries: list[dict[str, Any]]) list[dict[str, Any]]

Perform a list of update queries (source and components) to Store.

Each element of the queries list should conform to the specifications define by self.bulk_query.

This function will populate the LocalStore depending of the queries.

Parameters:
  • from_store – instance of an online store to query.

  • queries – a list of queries

Returns:

a list of answers