Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/cran/loader.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2021 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 datetime import timezone | from datetime import timezone | ||||
import logging | import logging | ||||
import os | import os | ||||
Show All 9 Lines | |||||
from swh.loader.package.utils import release_name | from swh.loader.package.utils import release_name | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Person, | Person, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
Sha1Git, | Sha1Git, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
from swh.storage.interface import StorageInterface | |||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
DATE_PATTERN = re.compile(r"^(?P<year>\d{4})-(?P<month>\d{2})$") | DATE_PATTERN = re.compile(r"^(?P<year>\d{4})-(?P<month>\d{2})$") | ||||
@attr.s | @attr.s | ||||
Show All 12 Lines | def from_metadata(cls, a_metadata: Dict[str, Any]) -> "CRANPackageInfo": | ||||
raw_info=a_metadata, | raw_info=a_metadata, | ||||
version=a_metadata["version"], | version=a_metadata["version"], | ||||
) | ) | ||||
class CRANLoader(PackageLoader[CRANPackageInfo]): | class CRANLoader(PackageLoader[CRANPackageInfo]): | ||||
visit_type = "cran" | visit_type = "cran" | ||||
def __init__(self, url: str, artifacts: List[Dict]): | def __init__( | ||||
self, | |||||
storage: StorageInterface, | |||||
url: str, | |||||
artifacts: List[Dict], | |||||
max_content_size: Optional[int] = None, | |||||
): | |||||
"""Loader constructor. | """Loader constructor. | ||||
Args: | Args: | ||||
url: Origin url to retrieve cran artifact(s) from | url: Origin url to retrieve cran artifact(s) from | ||||
artifacts: List of associated artifact for the origin url | artifacts: List of associated artifact for the origin url | ||||
""" | """ | ||||
super().__init__(url=url) | super().__init__(storage=storage, url=url, max_content_size=max_content_size) | ||||
# explicit what we consider the artifact identity | # explicit what we consider the artifact identity | ||||
self.artifacts = artifacts | self.artifacts = artifacts | ||||
def get_versions(self) -> List[str]: | def get_versions(self) -> List[str]: | ||||
versions = [] | versions = [] | ||||
for artifact in self.artifacts: | for artifact in self.artifacts: | ||||
versions.append(artifact["version"]) | versions.append(artifact["version"]) | ||||
return versions | return versions | ||||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |