swh.deposit.client module#

Module in charge of defining an swh-deposit client

swh.deposit.client.compute_unified_information(collection: str, in_progress: bool, slug: str, *, filepath: str | None = None, swhid: str | None = None, **kwargs) Dict[str, Any][source]#

Given a filepath, compute necessary information on that file.

Parameters:
  • collection – Deposit collection

  • in_progress – do we finalize the deposit?

  • slug – external id to use

  • filepath – Path to the file to compute the necessary information out of

  • swhid – Deposit swhid if any

Returns:

‘slug’: external id to use ‘in_progress’: do we finalize the deposit? ‘content-type’: content type associated ‘md5sum’: md5 sum ‘filename’: filename ‘filepath’: filepath ‘swhid’: deposit swhid

Return type:

dict with keys

exception swh.deposit.client.MaintenanceError[source]#

Bases: ValueError

Informational maintenance error exception

swh.deposit.client.handle_deprecated_config(config: Dict) Tuple[str, Tuple[str, str] | None][source]#
class swh.deposit.client.BaseApiDepositClient(config: Dict | None = None, url: str | None = None, auth: Tuple[str, str] | None = None)[source]#

Bases: object

Deposit client base class

do(method, url, *args, **kwargs)[source]#
Internal method to deal with requests, possibly with basic http

authentication.

Parameters:

method (str) – supported http methods as in self._methods’ keys

Returns:

The request’s execution

class swh.deposit.client.PrivateApiDepositClient(config: Dict | None = None, url: str | None = None, auth: Tuple[str, str] | None = None)[source]#

Bases: BaseApiDepositClient

Private API deposit client to:

  • read a given deposit’s archive(s)

  • read a given deposit’s metadata

  • update a given deposit’s status

archive_get(archive_update_url: str, archive: str) str | None[source]#

Retrieve the archive from the deposit to a local directory.

Parameters:
  • archive_update_url (str) – The full deposit archive(s)’s raw content to retrieve locally

  • archive (str) – the local archive’s path where to store

  • content (the raw)

Returns:

The archive path to the local archive to load. Or None if any problem arose.

metadata_get(metadata_url)[source]#

Retrieve the metadata information on a given deposit.

Parameters:
  • metadata_url (str) – The full deposit metadata url to retrieve

  • locally

Returns:

The dictionary of metadata for that deposit or None if any problem arose.

status_update(update_status_url, status, status_detail=None, release_id=None, directory_id=None, origin_url=None)[source]#

Update the deposit’s status.

Parameters:
  • update_status_url (str) – the full deposit’s archive

  • status (str) – The status to update the deposit with

  • release_id (str/None) – the release’s identifier to update to

  • directory_id (str/None) – the directory’s identifier to update to

  • origin_url (str/None) – deposit’s associated origin url

check(check_url)[source]#

Check the deposit’s associated data (metadata, archive(s))

Parameters:

check_url (str) – the full deposit’s check url

class swh.deposit.client.BaseDepositClient(config=None, url=None, auth=None, error_msg=None, empty_result={})[source]#

Bases: BaseApiDepositClient

Base Deposit client to access the public api.

compute_url(*args, **kwargs)[source]#

Compute api url endpoint to query.

compute_method(*args, **kwargs)[source]#

Http method to use on the url

parse_result_ok(xml_content: str, headers: Dict | None = None) Dict[str, Any][source]#

Given an xml result from the api endpoint, parse it and returns a dict.

compute_information(*args, **kwargs) Dict[str, Any][source]#

Compute some more information given the inputs (e.g http headers, …)

parse_result_error(xml_content: str) Dict[str, Any][source]#

Given an error response in xml, parse it into a dict.

Returns:

‘error’: The error message ‘detail’: Some more detail about the error if any

Return type:

dict with following keys

do_execute(method: str, url: str, info: Dict, **kwargs) Response[source]#

Execute the http query to url using method and info information.

By default, execute a simple query to url with the http method. Override this in subclass to improve the default behavior if needed.

compute_params(**kwargs) Dict[str, Any][source]#

Determine the params out of the kwargs

execute(*args, **kwargs) Dict[str, Any][source]#

Main endpoint to prepare and execute the http query to the api.

Raises:

MaintenanceError if some api maintenance is happening.

Returns:

Dict of computed api data

class swh.deposit.client.ServiceDocumentDepositClient(config=None, url=None, auth=None)[source]#

Bases: BaseDepositClient

Service Document information retrieval.

compute_url(*args, **kwargs)[source]#

Compute api url endpoint to query.

compute_method(*args, **kwargs)[source]#

Http method to use on the url

parse_result_ok(xml_content: str, headers: Dict | None = None) Dict[str, Any][source]#

Parse service document’s success response.

parse_result_error(xml_content: str) Dict[str, Any][source]#

Given an error response in xml, parse it into a dict.

Returns:

‘error’: The error message ‘detail’: Some more detail about the error if any

Return type:

dict with following keys

class swh.deposit.client.StatusDepositClient(config=None, url=None, auth=None)[source]#

Bases: BaseDepositClient

Status information on a deposit.

compute_url(collection, deposit_id)[source]#

Compute api url endpoint to query.

compute_method(*args, **kwargs)[source]#

Http method to use on the url

parse_result_ok(xml_content: str, headers: Dict | None = None) Dict[str, Any][source]#

Given an xml content as string, returns a deposit dict.

class swh.deposit.client.CollectionListDepositClient(config=None, url=None, auth=None)[source]#

Bases: BaseDepositClient

List a collection of deposits (owned by a user)

compute_url(collection, **kwargs)[source]#

Compute api url endpoint to query.

compute_method(*args, **kwargs)[source]#

Http method to use on the url

compute_params(**kwargs) Dict[str, Any][source]#

Transmit pagination params if values provided are not None (e.g. page, page_size)

parse_result_ok(xml_content: str, headers: Dict | None = None) Dict[str, Any][source]#

Given an xml content as string, returns a deposit dict.

class swh.deposit.client.BaseCreateDepositClient(config=None, url=None, auth=None)[source]#

Bases: BaseDepositClient

Deposit client base class to post new deposit.

compute_url(collection, *args, **kwargs)[source]#

Compute api url endpoint to query.

compute_method(*args, **kwargs)[source]#

Http method to use on the url

parse_result_ok(xml_content: str, headers: Dict | None = None) Dict[str, Any][source]#

Given an xml content as string, returns a deposit dict.

compute_headers(info: Dict[str, Any]) Dict[str, Any][source]#
do_execute(method, url, info, **kwargs)[source]#

Execute the http query to url using method and info information.

By default, execute a simple query to url with the http method. Override this in subclass to improve the default behavior if needed.

class swh.deposit.client.CreateArchiveDepositClient(config=None, url=None, auth=None)[source]#

Bases: BaseCreateDepositClient

Post an archive (binary) deposit client.

compute_headers(info)[source]#
compute_information(*args, **kwargs) Dict[str, Any][source]#

Compute some more information given the inputs (e.g http headers, …)

class swh.deposit.client.UpdateArchiveDepositClient(config=None, url=None, auth=None)[source]#

Bases: CreateArchiveDepositClient

Update (add/replace) an archive (binary) deposit client.

compute_url(collection, *args, deposit_id=None, **kwargs)[source]#

Compute api url endpoint to query.

compute_method(*args, replace=False, **kwargs)[source]#

Http method to use on the url

class swh.deposit.client.CreateMetadataDepositClient(config=None, url=None, auth=None)[source]#

Bases: BaseCreateDepositClient

Post a metadata deposit client.

compute_headers(info)[source]#
compute_information(*args, **kwargs) Dict[str, Any][source]#

Compute some more information given the inputs (e.g http headers, …)

class swh.deposit.client.UpdateMetadataOnPartialDepositClient(config=None, url=None, auth=None)[source]#

Bases: CreateMetadataDepositClient

Update (add/replace) metadata on partial deposit scenario.

compute_url(collection, *args, deposit_id=None, **kwargs)[source]#

Compute api url endpoint to query.

compute_method(*args, replace: bool = False, **kwargs) str[source]#

Http method to use on the url

class swh.deposit.client.UpdateMetadataOnDoneDepositClient(config=None, url=None, auth=None)[source]#

Bases: CreateMetadataDepositClient

Update metadata on “done” deposit. This requires the deposit swhid.

compute_url(collection, *args, deposit_id=None, **kwargs)[source]#

Compute api url endpoint to query.

compute_headers(info: Dict[str, Any]) Dict[str, Any][source]#
compute_method(*args, **kwargs) str[source]#

Http method to use on the url

class swh.deposit.client.CreateMetadataOnlyDepositClient(config=None, url=None, auth=None)[source]#

Bases: BaseCreateDepositClient

Create metadata-only deposit.

compute_information(*args, **kwargs) Dict[str, Any][source]#

Compute some more information given the inputs (e.g http headers, …)

parse_result_ok(xml_content: str, headers: Dict | None = None) Dict[str, Any][source]#

Given an xml content as string, returns a deposit dict.

class swh.deposit.client.CreateMultipartDepositClient(config=None, url=None, auth=None)[source]#

Bases: BaseCreateDepositClient

Create a multipart deposit client.

compute_information(*args, **kwargs) Dict[str, Any][source]#

Compute some more information given the inputs (e.g http headers, …)

do_execute(method, url, info, **kwargs)[source]#

Execute the http query to url using method and info information.

By default, execute a simple query to url with the http method. Override this in subclass to improve the default behavior if needed.

class swh.deposit.client.UpdateMultipartDepositClient(config=None, url=None, auth=None)[source]#

Bases: CreateMultipartDepositClient

Update a multipart deposit client.

compute_url(collection, *args, deposit_id=None, **kwargs)[source]#

Compute api url endpoint to query.

compute_method(*args, replace=False, **kwargs)[source]#

Http method to use on the url

class swh.deposit.client.PublicApiDepositClient(config: Dict | None = None, url: str | None = None, auth: Tuple[str, str] | None = None)[source]#

Bases: BaseApiDepositClient

Public api deposit client.

service_document()[source]#

Retrieve service document endpoint’s information.

deposit_status(collection: str, deposit_id: int)[source]#

Retrieve status information on a deposit.

deposit_list(collection: str, page: int | None = None, page_size: int | None = None)[source]#

List deposits from the collection

deposit_create(collection: str, slug: str | None, archive: str | None = None, metadata: str | None = None, in_progress: bool = False)[source]#

Create a new deposit (archive, metadata, both as multipart).

deposit_update(collection: str, deposit_id: int, slug: str | None, archive: str | None = None, metadata: str | None = None, in_progress: bool = False, replace: bool = False, swhid: str | None = None)[source]#

Update (add/replace) existing deposit (archive, metadata, both).

deposit_metadata_only(collection: str, metadata: str | None = None)[source]#