swh.indexer.mimetype module

swh.indexer.mimetype.compute_mimetype_encoding(raw_content: bytes) → Dict[str, bytes][source]

Determine mimetype and encoding from the raw content.

Parameters

raw_content – content’s raw data

Returns

mimetype and encoding key and corresponding values.

Return type

dict

class swh.indexer.mimetype.MixinMimetypeIndexer[source]

Bases: object

Mixin mimetype indexer.

See MimetypeIndexer and MimetypePartitionIndexer

tool: Any
idx_storage: Any
ADDITIONAL_CONFIG = {'tools': ('dict', {'name': 'file', 'version': '1:5.30-1+deb9u1', 'configuration': {'type': 'library', 'debian-package': 'python3-magic'}}), 'write_batch_size': ('int', 1000)}
CONFIG_BASE_FILENAME = 'indexer/mimetype'
index(id: Union[bytes, Dict, swh.model.model.Revision], data: Optional[bytes] = None, **kwargs) → Dict[str, Any][source]

Index sha1s’ content and store result.

Parameters
  • id – content’s identifier

  • data – raw content in bytes

Returns

content’s mimetype; dict keys being

  • id: content’s identifier (sha1)

  • mimetype: mimetype in bytes

  • encoding: encoding in bytes

Return type

dict

persist_index_computations(results: List[Dict], policy_update: str) → Dict[str, int][source]

Persist the results in storage.

Parameters
  • results – list of content’s mimetype dicts (see index())

  • policy_update – either ‘update-dups’ or ‘ignore-dups’ to respectively update duplicates or ignore them

class swh.indexer.mimetype.MimetypeIndexer(config=None, **kw)[source]

Bases: swh.indexer.mimetype.MixinMimetypeIndexer, swh.indexer.indexer.ContentIndexer

Mimetype Indexer working on list of content identifiers.

It:

  • (optionally) filters out content already indexed (cf. filter())

  • reads content from objstorage per the content’s id (sha1)

  • computes {mimetype, encoding} from that content

  • stores result in storage

filter(ids)[source]

Filter out known sha1s and return only missing ones.

idx_storage: Any
class swh.indexer.mimetype.MimetypePartitionIndexer(config=None, **kw)[source]

Bases: swh.indexer.mimetype.MixinMimetypeIndexer, swh.indexer.indexer.ContentPartitionIndexer

Mimetype Range Indexer working on range of content identifiers.

It:

  • (optionally) filters out content already indexed (cf indexed_contents_in_partition())

  • reads content from objstorage per the content’s id (sha1)

  • computes {mimetype, encoding} from that content

  • stores result in storage

indexed_contents_in_partition(partition_id: int, nb_partitions: int, page_token: Optional[str] = None)swh.core.api.classes.PagedResult[bytes, str][source]

Retrieve indexed content ids within partition_id.

Parameters
  • partition_id – Index of the partition to fetch

  • nb_partitions – Total number of partitions to split into

  • page_token – opaque token used for pagination

Returns

PagedResult of Sha1. If next_page_token is None, there is no more data to fetch

idx_storage: Any