swh.storage.converters module

swh.storage.converters.author_to_db(author)[source]

Convert a swh-model author to its DB representation.

Parameters

author – a swh.model compatible author

Returns

a dictionary with three keys: author, fullname and email

Return type

dict

swh.storage.converters.db_to_author(fullname: Optional[bytes], name: Optional[bytes], email: Optional[bytes]) → Optional[Dict[str, Optional[bytes]]][source]

Convert the DB representation of an author to a swh-model author.

Parameters
  • fullname (bytes) – the author’s fullname

  • name (bytes) – the author’s name

  • email (bytes) – the author’s email

Returns

a dictionary with three keys (fullname, name and email), or None if all the arguments are None.

swh.storage.converters.git_headers_to_db(git_headers)[source]

Convert git headers to their database representation.

We convert the bytes to unicode by decoding them into utf-8 and replacing invalid utf-8 sequences with backslash escapes.

swh.storage.converters.db_to_git_headers(db_git_headers)[source]
swh.storage.converters.db_to_date(date, offset, neg_utc_offset)[source]

Convert the DB representation of a date to a swh-model compatible date.

Parameters
  • date (datetime.datetime) – a date pulled out of the database

  • offset (int) – an integer number of minutes representing an UTC offset

  • neg_utc_offset (boolean) – whether an utc offset is negative

Returns

a dict with three keys:

  • timestamp: a timestamp from UTC

  • offset: the number of minutes since UTC

  • negative_utc: whether a null UTC offset is negative

Return type

dict

swh.storage.converters.date_to_db(date_offset)[source]

Convert a swh-model date_offset to its DB representation.

Parameters

date_offset – a swh.model compatible date_offset

Returns

a dictionary with three keys:

  • timestamp: a date in ISO format

  • offset: the UTC offset in minutes

  • neg_utc_offset: a boolean indicating whether a null offset is negative or positive.

Return type

dict

swh.storage.converters.revision_to_db(rev)[source]

Convert a swh-model revision to its database representation.

swh.storage.converters.db_to_revision(db_revision)[source]

Convert a database representation of a revision to its swh-model representation.

swh.storage.converters.release_to_db(rel)[source]

Convert a swh-model release to its database representation.

swh.storage.converters.db_to_release(db_release)[source]

Convert a database representation of a release to its swh-model representation.

swh.storage.converters.origin_url_to_sha1(origin_url)[source]

Convert an origin URL to a sha1. Encodes URL to utf-8.