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: Optional[str] = None, swhid: Optional[str] = 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, Optional[Tuple[str, str]]][source]
class swh.deposit.client.BaseApiDepositClient(config: Optional[Dict] = None, url: Optional[str] = None, auth: Optional[Tuple[str, str]] = 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: Optional[Dict] = None, url: Optional[str] = None, auth: Optional[Tuple[str, str]] = None)[source]

Bases: swh.deposit.client.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, archive)[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

  • raw content (the) –

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, revision_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

  • revision_id (str/None) – the revision’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: swh.deposit.client.BaseApiDepositClient

Base Deposit client to access the public api.

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

Compute api url endpoint to query.

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

Http method to use on the url

abstract parse_result_ok(xml_content)[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)[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, url, info)[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 daughter class to improve the default behavior if needed.

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: swh.deposit.client.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)[source]

Parse service document’s success response.

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

Bases: swh.deposit.client.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)[source]

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

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

Bases: swh.deposit.client.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)[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)[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 daughter class to improve the default behavior if needed.

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

Bases: swh.deposit.client.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: swh.deposit.client.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: swh.deposit.client.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: swh.deposit.client.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: swh.deposit.client.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: swh.deposit.client.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)[source]

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

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

Bases: swh.deposit.client.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)[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 daughter class to improve the default behavior if needed.

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

Bases: swh.deposit.client.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: Optional[Dict] = None, url: Optional[str] = None, auth: Optional[Tuple[str, str]] = None)[source]

Bases: swh.deposit.client.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_create(collection: str, slug: Optional[str], archive: Optional[str] = None, metadata: Optional[str] = None, in_progress: bool = False)[source]

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

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

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

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