eradiate.data.AssetManager

class eradiate.data.AssetManager(cache_dir, unpack_dir, install_dir, base_uri, manifest=None, resource_aliases=NOTHING, installed=NOTHING)[source]

Bases: object

Lightweight package manager for Eradiate’s data files.

This class implements a basic package management system which can list, download, decompress and install resources that take the form of compressed archive files.

Parameters:
  • cache_dir (path-like) – Cache location on disk.

  • unpack_dir (Path) – Resource unpacking location on disk.

  • install_dir (path-like) – Install location on disk.

  • base_uri (str or path) – Base URI of remote storage.

Fields:
  • cache_dir (Path) – Cache location on disk.

  • unpack_dir (Path) – Resource unpacking location on disk.

  • install_dir (Path) – Install location on disk.

  • base_uri (str or path) – Base URI of remote storage.

Notes

By default, the unique asset manager instance eradiate.asset_manager is initialized based on user-specified configuration:

  • cache_dir<settings["data_path"]>/cached

  • unpack_dir<settings["data_path"]>/unpacked

  • install_dir<settings["data_path"]>/installed/eradiate-v<__version__>

  • base_urisettings["data_url"]

Examples

A single instance of the asset manager is available as eradiate.asset_manager:

>>> from eradiate import asset_manager
>>> asset_manager.update()
>>> asset_manager.install(["core", "panellus"])
clear(resource_ids=None, what='cached')[source]

Clear the cache directory and save up disk space.

Parameters:
  • resource_ids (str or list of str, optional) – Resource(s) for which to clear data. If unset, all data will be wiped.

  • what ({"cached", "unpacked", "installed", "all"}, optional) – One or several keywords that specify which part of the data to clear.

download(resource_ids, unpack=True, progressbar=True)[source]

Download a resource from remote storage to the cache directory.

Parameters:
  • resource_ids (str or list of str) – Resource ID(s) to download.

  • unpack (bool, default: True) – Unpack downloaded archive.

  • progressbar (bool, default: True) – If True, display a progress bar for the download task.

Notes

This function uses the pooch.retrieve() function under the hood.

info(show=False)[source]

Collect information about the asset manager.

Parameters:

show (bool) – If True, display information to the terminal. Otherwise, return it as a dictionary.

install(resource_ids, progressbar=True)[source]

Install a resource and make it available for consumption.

Parameters:
  • resource_ids (str or list of str) – Resource ID(s) to install. The system ensures that requested resources are downloaded and unpacked.

  • progressbar (bool, default: True) – If True, display a progress bar if a download task is triggered.

list(what='resources')[source]

Display the list available resources in the manifest and their state.

Parameters:

what ({"resources", "aliases", "all"}) – One or several keywords that specify what to show.

remove(resource_ids)[source]

Uninstall a single resource.

Parameters:

resource_ids (str or list of str) – Resource ID(s) to uninstall.

state(resource_ids)[source]

Return information about the state of one or several resources.

Each resource has the following possible states:

  • cached: the archive is downloaded and found in the cache directory;

  • unpacked: the archive is extracted to the unpack location;

  • installed: the resource is installed to the installation directory.

Parameters:

resource_ids (str or list of str) – One or several resource IDs. Aliases are resolved.

Returns:

dict – A dictionary mapping resolved resource IDs to corresponding ResourceState flags.

update(download=None)[source]

Update the manifest, either reading it from disk if offline or recent enough, or downloading it from remote storage.

Parameters:

download (bool, optional) – If True, download the manifest from remote storage first. If False, only read from disk. If None (unset), apply default policy (download if the file on disk is more than a day old and not in offline mode).

property installed_path

Path to the list of installed resources.

property manifest_path

Path to the manifest file.