Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/loader.py
# Copyright (C) 2020-2021 The Software Heritage developers | # Copyright (C) 2020-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 copy | import copy | ||||
import json | import json | ||||
import logging | import logging | ||||
import re | import re | ||||
from typing import Any, Dict, Iterator, List, Mapping, Optional, Tuple | from typing import Any, Dict, Iterator, List, Mapping, Optional, Set, Tuple | ||||
import attr | import attr | ||||
from swh.loader.package.loader import ( | from swh.loader.package.loader import ( | ||||
BasePackageInfo, | BasePackageInfo, | ||||
PackageLoader, | PackageLoader, | ||||
PartialExtID, | PartialExtID, | ||||
RawExtrinsicMetadataCore, | RawExtrinsicMetadataCore, | ||||
) | ) | ||||
from swh.loader.package.utils import EMPTY_AUTHOR, api_info, cached_method | from swh.loader.package.utils import EMPTY_AUTHOR, api_info, cached_method | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
MetadataAuthority, | MetadataAuthority, | ||||
MetadataAuthorityType, | MetadataAuthorityType, | ||||
ObjectType, | ObjectType, | ||||
Release, | Release, | ||||
Sha1Git, | Sha1Git, | ||||
) | ) | ||||
from swh.model.swhids import CoreSWHID | |||||
from swh.storage.interface import StorageInterface | from swh.storage.interface import StorageInterface | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
EXTID_TYPE = "subresource-integrity" | EXTID_TYPE = "subresource-integrity" | ||||
"""The ExtID is an ASCII string, as defined by | """The ExtID is an ASCII string, as defined by | ||||
https://w3c.github.io/webappsec-subresource-integrity/""" | https://w3c.github.io/webappsec-subresource-integrity/""" | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | def get_package_info(self, url) -> Iterator[Tuple[str, NixGuixPackageInfo]]: | ||||
# 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.integrity_by_url()[url] | integrity = self.integrity_by_url()[url] | ||||
p_info = NixGuixPackageInfo.from_metadata( | p_info = NixGuixPackageInfo.from_metadata( | ||||
{"url": url, "integrity": integrity}, version=url | {"url": url, "integrity": integrity}, version=url | ||||
) | ) | ||||
yield url, p_info | yield url, p_info | ||||
def select_extid_target( | |||||
self, p_info: NixGuixPackageInfo, extid_targets: Set[CoreSWHID] | |||||
) -> Optional[CoreSWHID]: | |||||
if extid_targets: | |||||
# The archive URL is part of the release name. As that URL is not | |||||
# intrinsic metadata, it means different releases may be created for | |||||
# the same SRI so they have the same extid. | |||||
# Therefore, we need to pick the one with the right URL. | |||||
releases = self.storage.release_get( | |||||
[target.object_id for target in extid_targets] | |||||
) | |||||
extid_targets = { | |||||
release.swhid() | |||||
for release in releases | |||||
if release is not None and release.name == p_info.version.encode() | |||||
} | |||||
return super().select_extid_target(p_info, extid_targets) | |||||
def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | ||||
"""We add a branch to the snapshot called 'evaluation' pointing to the | """We add a branch to the snapshot called 'evaluation' pointing to the | ||||
revision used to generate the sources.json file. This revision | revision used to generate the sources.json file. This revision | ||||
is specified in the sources.json file itself. For the nixpkgs | is specified in the sources.json file itself. For the nixpkgs | ||||
origin, this revision is coming from the | origin, this revision is coming from the | ||||
github.com/nixos/nixpkgs repository. | github.com/nixos/nixpkgs repository. | ||||
Note this repository is not loaded explicitly. So, this | Note this repository is not loaded explicitly. So, this | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |