Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/loader.py
Show All 13 Lines | |||||
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.collections import ImmutableDict | |||||
from swh.model.model import ( | from swh.model.model import ( | ||||
MetadataAuthority, | MetadataAuthority, | ||||
MetadataAuthorityType, | MetadataAuthorityType, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
Sha1Git, | Sha1Git, | ||||
Snapshot, | |||||
TargetType, | |||||
) | ) | ||||
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 82 Lines • ▼ Show 20 Lines | 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 | ||||
# 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.integrity_by_url()[url] | integrity = self.integrity_by_url()[url] | ||||
p_info = NixGuixPackageInfo.from_metadata({"url": url, "integrity": integrity}) | p_info = NixGuixPackageInfo.from_metadata({"url": url, "integrity": integrity}) | ||||
yield url, p_info | yield url, p_info | ||||
def known_artifacts( | |||||
self, snapshot: Optional[Snapshot] | |||||
) -> Dict[Sha1Git, Optional[ImmutableDict[str, object]]]: | |||||
"""Almost same implementation as the default one except it filters out the extra | |||||
"evaluation" branch which does not have the right metadata structure. | |||||
""" | |||||
if not snapshot: | |||||
return {} | |||||
# Skip evaluation revision which has no metadata | |||||
revs = [ | |||||
rev.target | |||||
for branch_name, rev in snapshot.branches.items() | |||||
if ( | |||||
rev | |||||
and rev.target_type == TargetType.REVISION | |||||
and branch_name != b"evaluation" | |||||
) | |||||
] | |||||
known_revisions = self.storage.revision_get(revs) | |||||
ret = {} | |||||
for revision in known_revisions: | |||||
if not revision: # revision_get can return None | |||||
continue | |||||
ret[revision.id] = revision.metadata | |||||
return ret | |||||
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 146 Lines • Show Last 20 Lines |