swh.loader.package.utils module#

swh.loader.package.utils.download(url: str, dest: str, hashes: Dict = {}, filename: str | None = None, auth: Tuple[str, str] | None = None, extra_request_headers: Dict[str, str] | None = None) Tuple[str, Dict][source]#

Download a remote file from url, and compute swh hashes on it.

Parameters:
  • url – Artifact uri to fetch and hash

  • dest – Directory to write the archive to

  • hashes – Dict of expected hashes (key is the hash algo) for the artifact to download (those hashes are expected to be hex string). The supported algorithms are defined in the swh.model.hashutil.ALGORITHMS set.

  • auth – Optional tuple of login/password (for http authentication service, e.g. deposit)

Raises:
  • ValueError in case of any error when fetching/computing (length,

  • checksums mismatched...)

Returns:

Tuple of local (filepath, hashes of filepath)

swh.loader.package.utils.get_url_body(url: str, **extra_params) bytes[source]#

Basic HTTP client to retrieve information on software package, typically JSON metadata from a REST API.

Parameters:

url (str) – An HTTP URL

Raises:

NotFound in case of query failures (for some reasons – 404, …)

Returns:

The associated response’s information

swh.loader.package.utils.release_name(version: str, filename: str | None = None) str[source]#
swh.loader.package.utils.cached_method(f: Callable[[TSelf], TReturn]) Callable[[TSelf], TReturn][source]#