Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/loader.py
Show All 23 Lines | |||||
from swh.loader.package.loader import BasePackageInfo, PackageLoader | from swh.loader.package.loader import BasePackageInfo, PackageLoader | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
@attr.s | @attr.s | ||||
class NixGuixPackageInfo(BasePackageInfo): | class NixGuixPackageInfo(BasePackageInfo): | ||||
raw = attr.ib(type=Dict[str, Any]) | raw_info = attr.ib(type=Dict[str, Any]) | ||||
integrity = attr.ib(type=str) | integrity = attr.ib(type=str) | ||||
"""Hash of the archive, formatted as in the Subresource Integrity | """Hash of the archive, formatted as in the Subresource Integrity | ||||
specification.""" | specification.""" | ||||
@classmethod | @classmethod | ||||
def from_metadata(cls, metadata: Dict[str, Any]) -> "NixGuixPackageInfo": | def from_metadata(cls, metadata: Dict[str, Any]) -> "NixGuixPackageInfo": | ||||
return cls( | return cls( | ||||
url=metadata["url"], | url=metadata["url"], | ||||
filename=None, | filename=None, | ||||
integrity=metadata["integrity"], | integrity=metadata["integrity"], | ||||
raw=metadata, | raw_info=metadata, | ||||
) | ) | ||||
class NixGuixLoader(PackageLoader[NixGuixPackageInfo]): | 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). | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | ) -> Optional[Revision]: | ||||
committer_date=None, | committer_date=None, | ||||
parents=(), | parents=(), | ||||
directory=directory, | directory=directory, | ||||
synthetic=True, | synthetic=True, | ||||
metadata={ | metadata={ | ||||
"extrinsic": { | "extrinsic": { | ||||
"provider": self.provider_url, | "provider": self.provider_url, | ||||
"when": self.visit_date.isoformat(), | "when": self.visit_date.isoformat(), | ||||
"raw": p_info.raw, | "raw": p_info.raw_info, | ||||
}, | }, | ||||
}, | }, | ||||
) | ) | ||||
def retrieve_sources(url: str) -> Dict[str, Any]: | def retrieve_sources(url: str) -> Dict[str, Any]: | ||||
response = requests.get(url, allow_redirects=True) | response = requests.get(url, allow_redirects=True) | ||||
if response.status_code != 200: | if response.status_code != 200: | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |