swh.indexer.storage.api.client module

class swh.indexer.storage.api.client.RemoteStorage(url, api_exception=None, timeout=None, chunk_size=4096, reraise_exceptions=None, **kwargs)[source]

Bases: swh.core.api.RPCClient

Proxy to a remote storage API

backend_class

alias of swh.indexer.storage.interface.IndexerStorageInterface

api_exception

alias of swh.indexer.storage.exc.IndexerStorageAPIError

reraise_exceptions: ClassVar[List[Type[Exception]]] = [<class 'swh.indexer.storage.exc.IndexerStorageArgumentException'>, <class 'swh.indexer.storage.exc.DuplicateId'>]
check_config(*, check_write)

Check that the storage is configured and ready to go.

content_ctags_add(ctags: List[Dict], conflict_update: bool = False) → Dict[str, int]

Add ctags not present in storage

Parameters

ctags (iterable) –

dictionaries with keys:

  • id (bytes): sha1

  • ctags ([list): List of dictionary with keys: name, kind, line, lang

Returns

Dict summary of number of rows added

content_ctags_get(ids)

Retrieve ctags per id.

Parameters

ids (iterable) – sha1 checksums

Yields

Dictionaries with keys – - id (bytes): content’s identifier - name (str): symbol’s name - kind (str): symbol’s kind - lang (str): language for that content - tool (dict): tool used to compute the ctags’ info

content_ctags_missing(ctags)

List ctags missing from storage.

Parameters

ctags (iterable) –

dicts with keys:

  • id (bytes): sha1 identifier

  • indexer_configuration_id (int): tool used to compute the results

Yields

an iterable of missing id for the tuple (id, indexer_configuration_id)

Search through content’s raw ctags symbols.

Parameters
  • expression (str) – Expression to search for

  • limit (int) – Number of rows to return (default to 10).

  • last_sha1 (str) – Offset from which retrieving data (default to ‘’).

Yields

rows of ctags including id, name, lang, kind, line, etc…

content_fossology_license_add(licenses: List[Dict], conflict_update: bool = False) → Dict[str, int]

Add licenses not present in storage.

Parameters
  • licenses (iterable) –

    dictionaries with keys:

    • id: sha1

    • licenses ([bytes]): List of licenses associated to sha1

    • tool (str): nomossa

  • conflict_update – Flag to determine if we want to overwrite (true) or skip duplicates (false, the default)

Returns

Dict summary of number of rows added

content_fossology_license_get(ids)

Retrieve licenses per id.

Parameters

ids (iterable) – sha1 checksums

Yields

dict{id: facts} where facts is a dict with the following keys:

  • licenses ([str]): associated licenses for that content

  • tool (dict): Tool used to compute the license

content_fossology_license_get_range(start, end, indexer_configuration_id, limit=1000)

Retrieve licenses within range [start, end] bound by limit.

Parameters
  • **start** (bytes) – Starting identifier range (expected smaller than end)

  • **end** (bytes) – Ending identifier range (expected larger than start)

  • **indexer_configuration_id** (int) – The tool used to index data

  • **limit** (int) – Limit result (default to 1000)

Raises

ValueError for limit to None

Returns

  • ids [bytes]: iterable of content ids within the range.

  • next (Optional[bytes]): The next range of sha1 starts at

    this sha1 if any

Return type

a dict with keys

content_language_add(languages: List[Dict], conflict_update: bool = False) → Dict[str, int]

Add languages not present in storage.

Parameters
  • languages (iterable) –

    dictionaries with keys:

    • id (bytes): sha1

    • lang (bytes): language detected

  • conflict_update (bool) – Flag to determine if we want to overwrite (true) or skip duplicates (false, the default)

Returns

Dict summary of number of rows added

content_language_get(ids)

Retrieve full content language per ids.

Parameters

ids (iterable) – sha1 identifier

Yields

languages (iterable)

dictionaries with keys:

  • id (bytes): sha1 identifier

  • lang (bytes): raw content’s language

  • tool (dict): Tool used to compute the language

content_language_missing(languages)

List languages missing from storage.

Parameters

languages (iterable) –

dictionaries with keys:

  • id (bytes): sha1 identifier

  • indexer_configuration_id (int): tool used to compute the results

Yields

an iterable of missing id for the tuple (id, indexer_configuration_id)

content_metadata_add(metadata: List[Dict], conflict_update: bool = False) → Dict[str, int]

Add metadata not present in storage.

Parameters
  • metadata (iterable) –

    dictionaries with keys:

    • id: sha1

    • metadata: arbitrary dict

  • conflict_update – Flag to determine if we want to overwrite (true) or skip duplicates (false, the default)

Returns

Dict summary of number of rows added

content_metadata_get(ids)

Retrieve metadata per id.

Parameters

ids (iterable) – sha1 checksums

Yields

dictionaries with the following keys – id (bytes) metadata (str): associated metadata tool (dict): tool used to compute metadata

content_metadata_missing(metadata)

List metadata missing from storage.

Parameters

metadata (iterable) –

dictionaries with keys:

  • id (bytes): sha1 identifier

  • indexer_configuration_id (int): tool used to compute the results

Yields

missing sha1s

content_mimetype_add(mimetypes: List[Dict], conflict_update: bool = False) → Dict[str, int]

Add mimetypes not present in storage.

Parameters

mimetypes (iterable) –

dictionaries with keys:

  • id (bytes): sha1 identifier

  • mimetype (bytes): raw content’s mimetype

  • encoding (bytes): raw content’s encoding

  • indexer_configuration_id (int): tool’s id used to compute the results

  • conflict_update (bool): Flag to determine if we want to overwrite (True) or skip duplicates (False, the default)

Returns

Dict summary of number of rows added

content_mimetype_get(ids)

Retrieve full content mimetype per ids.

Parameters

ids (iterable) – sha1 identifier

Yields

mimetypes (iterable)

dictionaries with keys:

  • id (bytes): sha1 identifier

  • mimetype (bytes): raw content’s mimetype

  • encoding (bytes): raw content’s encoding

  • tool (dict): Tool used to compute the language

content_mimetype_get_range(start, end, indexer_configuration_id, limit=1000)

Retrieve mimetypes within range [start, end] bound by limit.

Parameters
  • **start** (bytes) – Starting identifier range (expected smaller than end)

  • **end** (bytes) – Ending identifier range (expected larger than start)

  • **indexer_configuration_id** (int) – The tool used to index data

  • **limit** (int) – Limit result (default to 1000)

Raises

ValueError for limit to None

Returns

  • ids [bytes]: iterable of content ids within the range.

  • next (Optional[bytes]): The next range of sha1 starts at

    this sha1 if any

Return type

a dict with keys

content_mimetype_missing(mimetypes)

Generate mimetypes missing from storage.

Parameters

mimetypes (iterable) –

iterable of dict with keys:

  • id (bytes): sha1 identifier

  • indexer_configuration_id (int): tool used to compute the results

Yields

tuple (id, indexer_configuration_id) – missing id

indexer_configuration_add(tools)

Add new tools to the storage.

Parameters

tools ([dict]) –

List of dictionary representing tool to insert in the db. Dictionary with the following keys:

  • tool_name (str): tool’s name

  • tool_version (str): tool’s version

  • tool_configuration (dict): tool’s configuration (free form dict)

Returns

List of dict inserted in the db (holding the id key as well). The order of the list is not guaranteed to match the order of the initial list.

indexer_configuration_get(tool)

Retrieve tool information.

Parameters

tool (dict) –

Dictionary representing a tool with the following keys:

  • tool_name (str): tool’s name

  • tool_version (str): tool’s version

  • tool_configuration (dict): tool’s configuration (free form dict)

Returns

The same dictionary with an id key, None otherwise.

origin_intrinsic_metadata_add(metadata: List[Dict], conflict_update: bool = False) → Dict[str, int]

Add origin metadata not present in storage.

Parameters
  • metadata (iterable) –

    dictionaries with keys:

    • id: origin urls

    • from_revision: sha1 id of the revision used to generate these metadata.

    • metadata: arbitrary dict

    • indexer_configuration_id: tool used to compute metadata

    • mappings (List[str]): list of mappings used to translate these metadata

  • conflict_update – Flag to determine if we want to overwrite (true) or skip duplicates (false, the default)

Returns

Dict summary of number of rows added

origin_intrinsic_metadata_delete(entries: List[Dict]) → Dict

Remove origin metadata from the storage.

Parameters

entries (dict) –

dictionaries with the following keys:

  • id (str): origin urls

  • indexer_configuration_id (int): tool used to compute metadata

Returns

Summary of number of rows deleted

origin_intrinsic_metadata_get(ids)

Retrieve origin metadata per id.

Parameters

ids (iterable) – origin identifiers

Yields

list

dictionaries with the following keys:

  • id (str): origin url

  • from_revision (bytes): which revision this metadata was extracted from

  • metadata (str): associated metadata

  • tool (dict): tool used to compute metadata

  • mappings (List[str]): list of mappings used to translate these metadata

origin_intrinsic_metadata_search_by_producer(page_token='', limit=100, ids_only=False, mappings=None, tool_ids=None)

Returns the list of origins whose metadata contain all the terms.

Parameters
  • page_token (str) – Opaque token used for pagination.

  • limit (int) – The maximum number of results to return

  • ids_only (bool) – Determines whether only origin urls are returned or the content as well

  • mappings (List[str]) – Returns origins whose intrinsic metadata were generated using at least one of these mappings.

Returns

dict with the following keys:
  • next_page_token (str, optional): opaque token to be used as page_token for retrieving the next page. If absent, there is no more pages to gather.

  • origins (list): list of origin url (str) if ids_only=True else dictionaries with the following keys:

    • id (str): origin urls

    • from_revision: sha1 id of the revision used to generate these metadata.

    • metadata (str): associated metadata

    • tool (dict): tool used to compute metadata

    • mappings (List[str]): list of mappings used to translate these metadata

Return type

dict

origin_intrinsic_metadata_search_fulltext(conjunction, limit=100)

Returns the list of origins whose metadata contain all the terms.

Parameters
  • conjunction (List[str]) – List of terms to be searched for.

  • limit (int) – The maximum number of results to return

Yields

list

dictionaries with the following keys:

  • id (str): origin urls

  • from_revision: sha1 id of the revision used to generate these metadata.

  • metadata (str): associated metadata

  • tool (dict): tool used to compute metadata

  • mappings (List[str]): list of mappings used to translate these metadata

origin_intrinsic_metadata_stats()

Returns counts of indexed metadata per origins, broken down into metadata types.

Returns

dictionary with keys:

  • total (int): total number of origins that were indexed (possibly yielding an empty metadata dictionary)

  • non_empty (int): total number of origins that we extracted a non-empty metadata dictionary from

  • per_mapping (dict): a dictionary with mapping names as keys and number of origins whose indexing used this mapping. Note that indexing a given origin may use 0, 1, or many mappings.

Return type

dict

revision_intrinsic_metadata_add(metadata: List[Dict], conflict_update: bool = False) → Dict[str, int]

Add metadata not present in storage.

Parameters
  • metadata (iterable) –

    dictionaries with keys:

    • id: sha1_git of revision

    • metadata: arbitrary dict

    • indexer_configuration_id: tool used to compute metadata

    • mappings (List[str]): list of mappings used to translate these metadata

  • conflict_update – Flag to determine if we want to overwrite (true) or skip duplicates (false, the default)

Returns

Dict summary of number of rows added

revision_intrinsic_metadata_delete(entries: List[Dict]) → Dict

Remove revision metadata from the storage.

Parameters

entries (dict) –

dictionaries with the following keys:

  • id (bytes): revision identifier

  • indexer_configuration_id (int): tool used to compute metadata

Returns

Summary of number of rows deleted

revision_intrinsic_metadata_get(ids)

Retrieve revision metadata per id.

Parameters

ids (iterable) – sha1 checksums

Yields

dictionaries with the following keys:

  • id (bytes)

  • metadata (str): associated metadata

  • tool (dict): tool used to compute metadata

  • mappings (List[str]): list of mappings used to translate these metadata

revision_intrinsic_metadata_missing(metadata)

List metadata missing from storage.

Parameters

metadata (iterable) –

dictionaries with keys:

  • id (bytes): sha1_git revision identifier

  • indexer_configuration_id (int): tool used to compute the results

Yields

missing ids