Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/debian/loader.py
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | if len(new_dsc_files) != 1: | ||||
raise ValueError( | raise ValueError( | ||||
f"Expected exactly one new .dsc file for package {p_info.name}, " | f"Expected exactly one new .dsc file for package {p_info.name}, " | ||||
f"got {len(new_dsc_files)}" | f"got {len(new_dsc_files)}" | ||||
) | ) | ||||
new_dsc_sha256 = new_dsc_files[0].sha256 | new_dsc_sha256 = new_dsc_files[0].sha256 | ||||
for rev_id, known_artifacts in known_package_artifacts.items(): | for rev_id, known_artifacts in known_package_artifacts.items(): | ||||
if new_dsc_sha256 == _artifact_to_dsc_sha256(known_artifacts, p_info.url): | |||||
return rev_id | |||||
return None | |||||
def _artifact_to_dsc_sha256(known_artifacts: Dict, url: str) -> Optional[str]: | |||||
extrinsic = known_artifacts.get("extrinsic") | extrinsic = known_artifacts.get("extrinsic") | ||||
if not extrinsic: | if not extrinsic: | ||||
continue | return None | ||||
known_p_info = DebianPackageInfo.from_metadata(extrinsic["raw"], url=p_info.url) | known_p_info = DebianPackageInfo.from_metadata(extrinsic["raw"], url=url) | ||||
dsc = [ | dsc = [file for (name, file) in known_p_info.files.items() if name.endswith(".dsc")] | ||||
file for (name, file) in known_p_info.files.items() if name.endswith(".dsc") | |||||
] | |||||
if len(dsc) != 1: | if len(dsc) != 1: | ||||
raise ValueError( | raise ValueError( | ||||
f"Expected exactly one known .dsc file for package {p_info.name}, " | f"Expected exactly one known .dsc file for package {known_p_info.name}, " | ||||
f"got {len(dsc)}" | f"got {len(dsc)}" | ||||
) | ) | ||||
if new_dsc_sha256 == dsc[0].sha256: | return dsc[0].sha256 | ||||
return rev_id | |||||
return None | |||||
def uid_to_person(uid: str) -> Dict[str, str]: | def uid_to_person(uid: str) -> Dict[str, str]: | ||||
"""Convert an uid to a person suitable for insertion. | """Convert an uid to a person suitable for insertion. | ||||
Args: | Args: | ||||
uid: an uid of the form "Name <email@ddress>" | uid: an uid of the form "Name <email@ddress>" | ||||
▲ Show 20 Lines • Show All 212 Lines • Show Last 20 Lines |