Changeset View
Changeset View
Standalone View
Standalone View
swh/clearlydefined/mapping_utils.py
Show All 36 Lines | class ToolType(Enum): | ||||
DEFINITION = "definition" | DEFINITION = "definition" | ||||
SCANCODE = "scancode" | SCANCODE = "scancode" | ||||
CLEARLYDEFINED = "clearlydefined" | CLEARLYDEFINED = "clearlydefined" | ||||
LICENSEE = "licensee" | LICENSEE = "licensee" | ||||
FOSSOLOGY = "fossology" | FOSSOLOGY = "fossology" | ||||
AUTHORITY = MetadataAuthority( | |||||
type=MetadataAuthorityType.REGISTRY, | |||||
url="https://clearlydefined.io/", | |||||
metadata={}, | |||||
) | |||||
FETCHER = MetadataFetcher( | |||||
name="swh-clearlydefined", | |||||
version="0.0.1", | |||||
metadata={}, | |||||
) | |||||
def map_row_data_with_metadata( | def map_row_data_with_metadata( | ||||
swh_id: str, | swh_id: str, | ||||
type: MetadataTargetType, | type: MetadataTargetType, | ||||
origin: Optional[Origin], | origin: Optional[Origin], | ||||
metadata: Dict, | metadata: Dict, | ||||
date: datetime, | date: datetime, | ||||
format: str, | format: str, | ||||
) -> RawExtrinsicMetadata: | ) -> RawExtrinsicMetadata: | ||||
""" | """ | ||||
Take and data_list as input and write | Take and data_list as input and write | ||||
data inside RawExtrensicMetadata table inside | data inside RawExtrensicMetadata table inside | ||||
swh storage | swh storage | ||||
""" | """ | ||||
return RawExtrinsicMetadata( | return RawExtrinsicMetadata( | ||||
type=type, | type=type, | ||||
target=parse_swhid(swh_id), | target=parse_swhid(swh_id), | ||||
discovery_date=date, | discovery_date=date, | ||||
authority=attr.evolve(authority, metadata=None), | authority=attr.evolve(AUTHORITY, metadata=None), | ||||
fetcher=attr.evolve(fetcher, metadata=None), | fetcher=attr.evolve(FETCHER, metadata=None), | ||||
format=format, | format=format, | ||||
origin=origin.url if origin else None, | origin=origin.url if origin else None, | ||||
metadata=json.dumps(metadata).encode("utf-8"), | metadata=json.dumps(metadata).encode("utf-8"), | ||||
) | ) | ||||
authority = MetadataAuthority( | |||||
type=MetadataAuthorityType.REGISTRY, | |||||
url="https://clearlydefined.io/", | |||||
metadata={}, | |||||
) | |||||
fetcher = MetadataFetcher( | |||||
name="swh-clearlydefined", | |||||
version="0.0.1", | |||||
metadata={}, | |||||
) | |||||
def map_sha1_with_swhid(storage, sha1: str) -> Optional[str]: | def map_sha1_with_swhid(storage, sha1: str) -> Optional[str]: | ||||
""" | """ | ||||
Take sha1 and storage as input and give the corresponding | Take sha1 and storage as input and give the corresponding | ||||
swhID for that sha1 | swhID for that sha1 | ||||
""" | """ | ||||
if not sha1: | if not sha1: | ||||
return None | return None | ||||
content = storage.content_get([hash_to_bytes(sha1)])[0] | content = storage.content_get([hash_to_bytes(sha1)])[0] | ||||
▲ Show 20 Lines • Show All 255 Lines • Show Last 20 Lines |