Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/debian/loader.py
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
@attr.s | @attr.s | ||||
class DebianPackageInfo(BasePackageInfo): | class DebianPackageInfo(BasePackageInfo): | ||||
raw_info = attr.ib(type=Dict[str, Any]) | raw_info = attr.ib(type=Dict[str, Any]) | ||||
files = attr.ib(type=Dict[str, DebianFileMetadata]) | files = attr.ib(type=Dict[str, DebianFileMetadata]) | ||||
"""Metadata of the files (.deb, .dsc, ...) of the package.""" | """Metadata of the files (.deb, .dsc, ...) of the package.""" | ||||
name = attr.ib(type=str) | name = attr.ib(type=str) | ||||
version = attr.ib(type=str) | full_version = attr.ib(type=str) | ||||
"""eg. stretch/contrib/0.7.2-3""" | |||||
@classmethod | @classmethod | ||||
def from_metadata(cls, a_metadata: Dict[str, Any], url: str) -> "DebianPackageInfo": | def from_metadata( | ||||
cls, a_metadata: Dict[str, Any], url: str, version: str | |||||
) -> "DebianPackageInfo": | |||||
return cls( | return cls( | ||||
url=url, | url=url, | ||||
filename=None, | filename=None, | ||||
version=version, | |||||
raw_info=a_metadata, | raw_info=a_metadata, | ||||
files={ | files={ | ||||
file_name: DebianFileMetadata(**file_metadata) | file_name: DebianFileMetadata(**file_metadata) | ||||
for (file_name, file_metadata) in a_metadata.get("files", {}).items() | for (file_name, file_metadata) in a_metadata.get("files", {}).items() | ||||
}, | }, | ||||
name=a_metadata["name"], | name=a_metadata["name"], | ||||
version=a_metadata["version"], | full_version=a_metadata["version"], | ||||
) | ) | ||||
def extid(self) -> Optional[PartialExtID]: | def extid(self) -> Optional[PartialExtID]: | ||||
dsc_files = [ | dsc_files = [ | ||||
file for (name, file) in self.files.items() if name.endswith(".dsc") | file for (name, file) in self.files.items() if name.endswith(".dsc") | ||||
] | ] | ||||
if len(dsc_files) != 1: | if len(dsc_files) != 1: | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | def get_versions(self) -> Sequence[str]: | ||||
"""Returns the keys of the packages input (e.g. | """Returns the keys of the packages input (e.g. | ||||
stretch/contrib/0.7.2-3, etc...) | stretch/contrib/0.7.2-3, etc...) | ||||
""" | """ | ||||
return list(self.packages.keys()) | return list(self.packages.keys()) | ||||
def get_package_info(self, version: str) -> Iterator[Tuple[str, DebianPackageInfo]]: | def get_package_info(self, version: str) -> Iterator[Tuple[str, DebianPackageInfo]]: | ||||
meta = self.packages[version] | meta = self.packages[version] | ||||
p_info = DebianPackageInfo.from_metadata(meta, url=self.url) | p_info = DebianPackageInfo.from_metadata(meta, url=self.url, version=version) | ||||
yield release_name(version), p_info | yield release_name(version), p_info | ||||
def download_package( | def download_package( | ||||
self, p_info: DebianPackageInfo, tmpdir: str | self, p_info: DebianPackageInfo, tmpdir: str | ||||
) -> List[Tuple[str, Mapping]]: | ) -> List[Tuple[str, Mapping]]: | ||||
"""Contrary to other package loaders (1 package, 1 artifact), | """Contrary to other package loaders (1 package, 1 artifact), | ||||
`p_info.files` represents the package's datafiles set to fetch: | `p_info.files` represents the package's datafiles set to fetch: | ||||
- <package-version>.orig.tar.gz | - <package-version>.orig.tar.gz | ||||
Show All 13 Lines | class DebianLoader(PackageLoader[DebianPackageInfo]): | ||||
def uncompress( | def uncompress( | ||||
self, dl_artifacts: List[Tuple[str, Mapping[str, Any]]], dest: str | self, dl_artifacts: List[Tuple[str, Mapping[str, Any]]], dest: str | ||||
) -> str: | ) -> str: | ||||
logger.debug("dl_artifacts: %s", dl_artifacts) | logger.debug("dl_artifacts: %s", dl_artifacts) | ||||
return extract_package(dl_artifacts, dest=dest) | return extract_package(dl_artifacts, dest=dest) | ||||
def build_release( | def build_release( | ||||
self, | self, p_info: DebianPackageInfo, uncompressed_path: str, directory: Sha1Git, | ||||
version: str, | |||||
p_info: DebianPackageInfo, | |||||
uncompressed_path: str, | |||||
directory: Sha1Git, | |||||
) -> Optional[Release]: | ) -> Optional[Release]: | ||||
dsc_url, dsc_name = dsc_information(p_info) | dsc_url, dsc_name = dsc_information(p_info) | ||||
if not dsc_name: | if not dsc_name: | ||||
raise ValueError("dsc name for url %s should not be None" % dsc_url) | raise ValueError("dsc name for url %s should not be None" % dsc_url) | ||||
dsc_path = path.join(path.dirname(uncompressed_path), dsc_name) | dsc_path = path.join(path.dirname(uncompressed_path), dsc_name) | ||||
intrinsic_metadata = get_intrinsic_package_metadata( | intrinsic_metadata = get_intrinsic_package_metadata( | ||||
p_info, dsc_path, uncompressed_path | p_info, dsc_path, uncompressed_path | ||||
) | ) | ||||
logger.debug("intrinsic_metadata: %s", intrinsic_metadata) | logger.debug("intrinsic_metadata: %s", intrinsic_metadata) | ||||
logger.debug("p_info: %s", p_info) | logger.debug("p_info: %s", p_info) | ||||
msg = "Synthetic revision for Debian source package %s version %s" % ( | msg = "Synthetic revision for Debian source package %s version %s" % ( | ||||
p_info.name, | p_info.name, | ||||
p_info.version, | p_info.full_version, | ||||
) | ) | ||||
author = prepare_person(intrinsic_metadata.changelog.person) | author = prepare_person(intrinsic_metadata.changelog.person) | ||||
date = TimestampWithTimezone.from_iso8601(intrinsic_metadata.changelog.date) | date = TimestampWithTimezone.from_iso8601(intrinsic_metadata.changelog.date) | ||||
# inspired from swh.loader.debian.converters.package_metadata_to_revision | # inspired from swh.loader.debian.converters.package_metadata_to_revision | ||||
return Release( | return Release( | ||||
name=version.encode(), | name=p_info.version.encode(), | ||||
message=msg.encode("utf-8"), | message=msg.encode("utf-8"), | ||||
author=author, | author=author, | ||||
date=date, | date=date, | ||||
target=directory, | target=directory, | ||||
target_type=ObjectType.DIRECTORY, | target_type=ObjectType.DIRECTORY, | ||||
synthetic=True, | synthetic=True, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 219 Lines • Show Last 20 Lines |