Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/converters.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 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 Any, Dict, Optional | from typing import Any, Dict, Optional | ||||
import warnings | import warnings | ||||
from swh.core.utils import encode_with_unescape | from swh.core.utils import encode_with_unescape | ||||
from swh.model.identifiers import CoreSWHID, ExtendedSWHID | |||||
from swh.model.identifiers import ObjectType as SwhidObjectType | |||||
from swh.model.identifiers import origin_identifier | |||||
from swh.model.model import ( | from swh.model.model import ( | ||||
ExtID, | ExtID, | ||||
MetadataAuthority, | MetadataAuthority, | ||||
MetadataAuthorityType, | MetadataAuthorityType, | ||||
MetadataFetcher, | MetadataFetcher, | ||||
ObjectType, | ObjectType, | ||||
Origin, | |||||
Person, | Person, | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
Release, | Release, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
Timestamp, | Timestamp, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
from swh.model.swhids import CoreSWHID, ExtendedSWHID | |||||
from swh.model.swhids import ObjectType as SwhidObjectType | |||||
from ..utils import map_optional | from ..utils import map_optional | ||||
DEFAULT_AUTHOR = { | DEFAULT_AUTHOR = { | ||||
"fullname": None, | "fullname": None, | ||||
"name": None, | "name": None, | ||||
"email": None, | "email": None, | ||||
} | } | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | |||||
def db_to_raw_extrinsic_metadata(row) -> RawExtrinsicMetadata: | def db_to_raw_extrinsic_metadata(row) -> RawExtrinsicMetadata: | ||||
target = row["raw_extrinsic_metadata.target"] | target = row["raw_extrinsic_metadata.target"] | ||||
if not target.startswith("swh:1:"): | if not target.startswith("swh:1:"): | ||||
warnings.warn( | warnings.warn( | ||||
"Fetching raw_extrinsic_metadata row with URL target", DeprecationWarning | "Fetching raw_extrinsic_metadata row with URL target", DeprecationWarning | ||||
) | ) | ||||
target = "swh:1:ori:" + origin_identifier({"url": target}) | target = str(Origin(url=target).swhid()) | ||||
return RawExtrinsicMetadata( | return RawExtrinsicMetadata( | ||||
target=ExtendedSWHID.from_string(target), | target=ExtendedSWHID.from_string(target), | ||||
authority=MetadataAuthority( | authority=MetadataAuthority( | ||||
type=MetadataAuthorityType(row["metadata_authority.type"]), | type=MetadataAuthorityType(row["metadata_authority.type"]), | ||||
url=row["metadata_authority.url"], | url=row["metadata_authority.url"], | ||||
), | ), | ||||
fetcher=MetadataFetcher( | fetcher=MetadataFetcher( | ||||
Show All 25 Lines |