Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/archive/loader.py
# Copyright (C) 2019-2022 The Software Heritage developers | # Copyright (C) 2019-2022 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 | ||||
from __future__ import annotations | |||||
import datetime | import datetime | ||||
import hashlib | import hashlib | ||||
import logging | import logging | ||||
from os import path | from os import path | ||||
import string | import string | ||||
from typing import Any, Dict, Iterator, Mapping, Optional, Sequence, Tuple, Union | from typing import Any, Dict, Iterator, Mapping, Optional, Sequence, Tuple, Union | ||||
import attr | import attr | ||||
Show All 29 Lines | def extid(self, manifest_format: Optional[string.Template] = None) -> PartialExtID: | ||||
) | ) | ||||
return ( | return ( | ||||
self.EXTID_TYPE, | self.EXTID_TYPE, | ||||
self.EXTID_VERSION, | self.EXTID_VERSION, | ||||
hashlib.sha256(manifest.encode()).digest(), | hashlib.sha256(manifest.encode()).digest(), | ||||
) | ) | ||||
@classmethod | @classmethod | ||||
def from_metadata(cls, a_metadata: Dict[str, Any]) -> "ArchivePackageInfo": | def from_metadata(cls, a_metadata: Dict[str, Any]) -> ArchivePackageInfo: | ||||
url = a_metadata["url"] | url = a_metadata["url"] | ||||
filename = a_metadata.get("filename") | filename = a_metadata.get("filename") | ||||
return cls( | return cls( | ||||
url=url, | url=url, | ||||
filename=filename if filename else path.split(url)[-1], | filename=filename if filename else path.split(url)[-1], | ||||
raw_info=a_metadata, | raw_info=a_metadata, | ||||
length=a_metadata["length"], | length=a_metadata["length"], | ||||
time=a_metadata["time"], | time=a_metadata["time"], | ||||
version=a_metadata["version"], | version=a_metadata["version"], | ||||
checksums={"length": a_metadata["length"]}, | |||||
) | ) | ||||
class ArchiveLoader(PackageLoader[ArchivePackageInfo]): | class ArchiveLoader(PackageLoader[ArchivePackageInfo]): | ||||
"""Load archive origin's artifact files into swh archive""" | """Load archive origin's artifact files into swh archive""" | ||||
visit_type = "tar" | visit_type = "tar" | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |