Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/cpan/loader.py
Show All 9 Lines | |||||
import attr | import attr | ||||
import iso8601 | import iso8601 | ||||
from packaging.version import parse as parse_version | from packaging.version import parse as parse_version | ||||
from requests import HTTPError | from requests import HTTPError | ||||
from swh.loader.package.loader import ( | from swh.loader.package.loader import ( | ||||
BasePackageInfo, | BasePackageInfo, | ||||
PackageLoader, | PackageLoader, | ||||
PartialExtID, | |||||
RawExtrinsicMetadataCore, | RawExtrinsicMetadataCore, | ||||
) | ) | ||||
from swh.loader.package.utils import EMPTY_AUTHOR, Person, get_url_body, release_name | from swh.loader.package.utils import EMPTY_AUTHOR, Person, get_url_body, release_name | ||||
from swh.model.hashutil import hash_to_bytes | |||||
from swh.model.model import ( | from swh.model.model import ( | ||||
MetadataAuthority, | MetadataAuthority, | ||||
MetadataAuthorityType, | MetadataAuthorityType, | ||||
ObjectType, | ObjectType, | ||||
Release, | Release, | ||||
Sha1Git, | Sha1Git, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
from swh.storage.interface import StorageInterface | from swh.storage.interface import StorageInterface | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
EXTID_TYPE = "cpan-archive-sha256" | |||||
EXTID_VERSION = 0 | |||||
@attr.s | @attr.s | ||||
class CpanPackageInfo(BasePackageInfo): | class CpanPackageInfo(BasePackageInfo): | ||||
name = attr.ib(type=str) | name = attr.ib(type=str) | ||||
"""Name of the package""" | """Name of the package""" | ||||
version = attr.ib(type=str) | version = attr.ib(type=str) | ||||
"""Current version""" | """Current version""" | ||||
last_modified = attr.ib(type=datetime) | last_modified = attr.ib(type=datetime) | ||||
"""File last modified date as release date.""" | """File last modified date as release date.""" | ||||
author = attr.ib(type=Person) | author = attr.ib(type=Person) | ||||
"""Author""" | """Author""" | ||||
def extid(self) -> PartialExtID: | |||||
return (EXTID_TYPE, EXTID_VERSION, hash_to_bytes(self.checksums["sha256"])) | |||||
class CpanLoader(PackageLoader[CpanPackageInfo]): | class CpanLoader(PackageLoader[CpanPackageInfo]): | ||||
visit_type = "cpan" | visit_type = "cpan" | ||||
EXTRINSIC_METADATA_URL_PATTERN = "{api_base_url}/release/{author}/{release_name}" | EXTRINSIC_METADATA_URL_PATTERN = "{api_base_url}/release/{author}/{release_name}" | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |