Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/converters.py
Show All 32 Lines | def author_to_db(author): | ||||
""" | """ | ||||
if author is None: | if author is None: | ||||
return DEFAULT_AUTHOR | return DEFAULT_AUTHOR | ||||
return author | return author | ||||
def db_to_author(id, fullname, name, email): | def db_to_author(fullname, name, email): | ||||
"""Convert the DB representation of an author to a swh-model author. | """Convert the DB representation of an author to a swh-model author. | ||||
Args: | Args: | ||||
id (long): the author's identifier | id (long): the author's identifier | ||||
fullname (bytes): the author's fullname | fullname (bytes): the author's fullname | ||||
name (bytes): the author's name | name (bytes): the author's name | ||||
email (bytes): the author's email | email (bytes): the author's email | ||||
Returns: | Returns: | ||||
dict: a dictionary with four keys: id, fullname, name and email, or | dict: a dictionary with four keys: id, fullname, name and email, or | ||||
None if the id is None | None if the id is None | ||||
""" | """ | ||||
if id is None: | |||||
return None | |||||
return { | return { | ||||
'id': id, | |||||
'fullname': fullname, | 'fullname': fullname, | ||||
'name': name, | 'name': name, | ||||
'email': email, | 'email': email, | ||||
} | } | ||||
def git_headers_to_db(git_headers): | def git_headers_to_db(git_headers): | ||||
"""Convert git headers to their database representation. | """Convert git headers to their database representation. | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | def revision_to_db(revision): | ||||
} | } | ||||
def db_to_revision(db_revision): | def db_to_revision(db_revision): | ||||
"""Convert a database representation of a revision to its swh-model | """Convert a database representation of a revision to its swh-model | ||||
representation.""" | representation.""" | ||||
author = db_to_author( | author = db_to_author( | ||||
db_revision['author_id'], | |||||
db_revision['author_fullname'], | db_revision['author_fullname'], | ||||
db_revision['author_name'], | db_revision['author_name'], | ||||
db_revision['author_email'], | db_revision['author_email'], | ||||
) | ) | ||||
date = db_to_date( | date = db_to_date( | ||||
db_revision['date'], | db_revision['date'], | ||||
db_revision['date_offset'], | db_revision['date_offset'], | ||||
db_revision['date_neg_utc_offset'], | db_revision['date_neg_utc_offset'], | ||||
) | ) | ||||
committer = db_to_author( | committer = db_to_author( | ||||
db_revision['committer_id'], | |||||
db_revision['committer_fullname'], | db_revision['committer_fullname'], | ||||
db_revision['committer_name'], | db_revision['committer_name'], | ||||
db_revision['committer_email'], | db_revision['committer_email'], | ||||
) | ) | ||||
committer_date = db_to_date( | committer_date = db_to_date( | ||||
db_revision['committer_date'], | db_revision['committer_date'], | ||||
db_revision['committer_date_offset'], | db_revision['committer_date_offset'], | ||||
db_revision['committer_date_neg_utc_offset'] | db_revision['committer_date_neg_utc_offset'] | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
def db_to_release(db_release): | def db_to_release(db_release): | ||||
"""Convert a database representation of a release to its swh-model | """Convert a database representation of a release to its swh-model | ||||
representation. | representation. | ||||
""" | """ | ||||
author = db_to_author( | author = db_to_author( | ||||
db_release['author_id'], | |||||
db_release['author_fullname'], | db_release['author_fullname'], | ||||
db_release['author_name'], | db_release['author_name'], | ||||
db_release['author_email'], | db_release['author_email'], | ||||
) | ) | ||||
date = db_to_date( | date = db_to_date( | ||||
db_release['date'], | db_release['date'], | ||||
db_release['date_offset'], | db_release['date_offset'], | ||||
db_release['date_neg_utc_offset'] | db_release['date_neg_utc_offset'] | ||||
Show All 17 Lines |