swh.deposit.client module

Module in charge of defining an swh-deposit client

exception swh.deposit.client.MaintenanceError[source]

Bases: ValueError

Informational maintenance error exception

class swh.deposit.client.BaseApiDepositClient(config=None, _client=<module 'requests' from '/home/jenkins/workspace/DDOC/publish/swh-docs/.tox/sphinx/lib/python3.7/site-packages/requests/__init__.py'>)[source]

Bases: swh.core.config.SWHConfig

Deposit client base class

CONFIG_BASE_FILENAME = 'deposit/client'
DEFAULT_CONFIG = {'auth': ('dict', {}), 'url': ('str', 'http://localhost:5006')}
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=None, _client=<module 'requests' from '/home/jenkins/workspace/DDOC/publish/swh-docs/.tox/sphinx/lib/python3.7/site-packages/requests/__init__.py'>)[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, 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)[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)[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)[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)[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_information(collection, filepath, in_progress, slug, is_archive=True, **kwargs)[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.CreateArchiveDepositClient(config)[source]

Bases: swh.deposit.client.BaseCreateDepositClient

Post an archive (binary) deposit client.

compute_headers(info)[source]
class swh.deposit.client.UpdateArchiveDepositClient(config)[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)[source]

Bases: swh.deposit.client.BaseCreateDepositClient

Post a metadata deposit client.

compute_headers(info)[source]
class swh.deposit.client.UpdateMetadataDepositClient(config)[source]

Bases: swh.deposit.client.CreateMetadataDepositClient

Update (add/replace) a metadata 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.CreateMultipartDepositClient(config)[source]

Bases: swh.deposit.client.BaseCreateDepositClient

Create a multipart deposit client.

compute_information(collection, archive, metadata, in_progress, slug, **kwargs)[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)[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=None, _client=<module 'requests' from '/home/jenkins/workspace/DDOC/publish/swh-docs/.tox/sphinx/lib/python3.7/site-packages/requests/__init__.py'>)[source]

Bases: swh.deposit.client.BaseApiDepositClient

Public api deposit client.

service_document()[source]

Retrieve service document endpoint’s information.

deposit_status(collection, deposit_id)[source]

Retrieve status information on a deposit.

deposit_create(collection, slug, archive=None, metadata=None, in_progress=False)[source]

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

deposit_update(collection, deposit_id, slug, archive=None, metadata=None, in_progress=False, replace=False)[source]

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