Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/converters.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-2019 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 Affero General Public License version 3, or any later version | # License: GNU Affero 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 | ||||
import json | import json | ||||
from typing import Dict, Any | |||||
from swh.model import hashutil | |||||
from swh.core.utils import decode_with_escape | from swh.core.utils import decode_with_escape | ||||
from swh.model import hashutil | |||||
from swh.web.common.typing import OriginInfo, OriginVisitInfo | |||||
def _group_checksums(data): | def _group_checksums(data): | ||||
"""Groups checksums values computed from hash functions used in swh | """Groups checksums values computed from hash functions used in swh | ||||
and stored in data dict under a single entry 'checksums' | and stored in data dict under a single entry 'checksums' | ||||
""" | """ | ||||
if data: | if data: | ||||
checksums = {} | checksums = {} | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | for key, value in dict_swh.items(): | ||||
else: | else: | ||||
new_dict[key] = value | new_dict[key] = value | ||||
_group_checksums(new_dict) | _group_checksums(new_dict) | ||||
return new_dict | return new_dict | ||||
def from_origin(origin): | def from_origin(origin: Dict[str, Any]) -> OriginInfo: | ||||
"""Convert from a swh origin to an origin dictionary. | """Convert from a swh origin to an origin dictionary. | ||||
""" | """ | ||||
return from_swh(origin) | return from_swh(origin) | ||||
def from_release(release): | def from_release(release): | ||||
"""Convert from a swh release to a json serializable release dictionary. | """Convert from a swh release to a json serializable release dictionary. | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | |||||
def from_person(person): | def from_person(person): | ||||
"""Convert swh person to serializable person dictionary. | """Convert swh person to serializable person dictionary. | ||||
""" | """ | ||||
return from_swh(person, bytess={"name", "fullname", "email"}) | return from_swh(person, bytess={"name", "fullname", "email"}) | ||||
def from_origin_visit(visit): | def from_origin_visit(visit: Dict[str, Any]) -> OriginVisitInfo: | ||||
"""Convert swh origin_visit to serializable origin_visit dictionary. | """Convert swh origin_visit to serializable origin_visit dictionary. | ||||
""" | """ | ||||
ov = from_swh( | ov = from_swh( | ||||
visit, | visit, | ||||
hashess={"target", "snapshot"}, | hashess={"target", "snapshot"}, | ||||
bytess={"branch"}, | bytess={"branch"}, | ||||
dates={"date"}, | dates={"date"}, | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |