Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/converters.py
# Copyright (C) 2015 The Software Heritage developers | # Copyright (C) 2015 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import datetime | import datetime | ||||
from typing import Optional, Dict | |||||
from swh.core.utils import decode_with_escape, encode_with_unescape | from swh.core.utils import decode_with_escape, encode_with_unescape | ||||
from swh.model import identifiers | from swh.model import identifiers | ||||
from swh.model.hashutil import MultiHash | from swh.model.hashutil import MultiHash | ||||
DEFAULT_AUTHOR = { | DEFAULT_AUTHOR = { | ||||
"fullname": None, | "fullname": None, | ||||
"name": None, | "name": None, | ||||
Show All 18 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(fullname, name, email): | def db_to_author( | ||||
fullname: Optional[bytes], name: Optional[bytes], email: Optional[bytes] | |||||
) -> Optional[Dict[str, Optional[bytes]]]: | |||||
"""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 | |||||
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 | a dictionary with three keys (fullname, name and email), or | ||||
None if the id is None | None if all the arguments are None. | ||||
""" | """ | ||||
if (fullname, name, email) == (None, None, None): | |||||
return None | |||||
return { | return { | ||||
"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): | ||||
▲ Show 20 Lines • Show All 253 Lines • Show Last 20 Lines |