Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/loader.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 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 json | import json | ||||
import logging | import logging | ||||
import requests | import requests | ||||
from typing import Any, Dict, Iterator, Mapping, Optional, Tuple | |||||
from typing import Dict, Optional, Any, Mapping | import attr | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
TargetType, | TargetType, | ||||
Snapshot, | Snapshot, | ||||
BaseModel, | BaseModel, | ||||
Sha1Git, | Sha1Git, | ||||
) | ) | ||||
from swh.loader.package.utils import EMPTY_AUTHOR | from swh.loader.package.utils import EMPTY_AUTHOR | ||||
from swh.loader.package.loader import PackageLoader | from swh.loader.package.loader import BasePackageInfo, PackageLoader | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
class NixGuixLoader(PackageLoader): | class NixGuixPackageInfo(BasePackageInfo): | ||||
raw = attr.ib(type=Dict[str, Any]) | |||||
class NixGuixLoader(PackageLoader[NixGuixPackageInfo]): | |||||
"""Load sources from a sources.json file. This loader is used to load | """Load sources from a sources.json file. This loader is used to load | ||||
sources used by functional package manager (eg. Nix and Guix). | sources used by functional package manager (eg. Nix and Guix). | ||||
""" | """ | ||||
visit_type = "nixguix" | visit_type = "nixguix" | ||||
def __init__(self, url): | def __init__(self, url): | ||||
Show All 16 Lines | def get_versions(self): | ||||
"""The first mirror of the mirror list is used as branch name in the | """The first mirror of the mirror list is used as branch name in the | ||||
snapshot. | snapshot. | ||||
""" | """ | ||||
return self._integrityByUrl.keys() | return self._integrityByUrl.keys() | ||||
# Note: this could be renamed get_artifact_info in the PackageLoader | # Note: this could be renamed get_artifact_info in the PackageLoader | ||||
# base class. | # base class. | ||||
def get_package_info(self, url): | def get_package_info(self, url) -> Iterator[Tuple[str, NixGuixPackageInfo]]: | ||||
# TODO: try all mirrors and not only the first one. A source | # TODO: try all mirrors and not only the first one. A source | ||||
ardumont: Iterator... | |||||
# can be fetched from several urls, called mirrors. We | # can be fetched from several urls, called mirrors. We | ||||
# currently only use the first one, but if the first one | # currently only use the first one, but if the first one | ||||
# fails, we should try the second one and so on. | # fails, we should try the second one and so on. | ||||
integrity = self._integrityByUrl[url] | integrity = self._integrityByUrl[url] | ||||
yield url, {"url": url, "raw": {"url": url, "integrity": integrity}} | p_info = NixGuixPackageInfo( | ||||
url=url, filename=None, raw={"url": url, "integrity": integrity}, | |||||
) | |||||
yield url, p_info | |||||
def known_artifacts(self, snapshot: Optional[Snapshot]) -> Dict[Sha1Git, BaseModel]: | def known_artifacts(self, snapshot: Optional[Snapshot]) -> Dict[Sha1Git, BaseModel]: | ||||
"""Almost same implementation as the default one except it filters out the extra | """Almost same implementation as the default one except it filters out the extra | ||||
"evaluation" branch which does not have the right metadata structure. | "evaluation" branch which does not have the right metadata structure. | ||||
""" | """ | ||||
if not snapshot: | if not snapshot: | ||||
return {} | return {} | ||||
▲ Show 20 Lines • Show All 157 Lines • Show Last 20 Lines |
Iterator...