From 58e77f47adf737c27e87e185adfe437dfebed6df Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 6 Jul 2021 13:51:41 +0200 Subject: mmdebstrap and sbuild shall agree on what build_path means While mmdebstrap would extract the package precisely to the build_path, sbuild would create a subdirectory - inside the build_path. Changing sbuild to do the mmdebstrap behaviour looks next to impossible, so this commit changes mmdebstrap to behave like sbuild. pbuilder also allows changing the build_path in principle. The documented BUILDDIR variable works quite similar to the sbuild option --build-path. pbuilder also allows changing the sub directory using the undocumented BUILDSUBDIR variable. That's another reason to do it like sbuild. --- mdbp/common.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'mdbp/common.py') diff --git a/mdbp/common.py b/mdbp/common.py index 719a8b6..5c67f58 100644 --- a/mdbp/common.py +++ b/mdbp/common.py @@ -118,6 +118,11 @@ def download(uri: str, checksums: typing.Dict[str, str], dest.unlink() raise +def parse_dsc(dscpath: pathlib.Path) -> debian.deb822.Dsc: + """Parse a dsc file.""" + with dscpath.open("r") as dscf: + return debian.deb822.Dsc(dscf) + def download_dsc(buildinput: JsonObject, destdir: pathlib.Path) -> pathlib.Path: """Download the .input.source_package_url including referenced components @@ -130,12 +135,11 @@ def download_dsc(buildinput: JsonObject, assert isinstance(dscpath, pathlib.Path) download(dscuri, buildinput.get("checksums", {}), dscpath) files: typing.Dict[str, typing.Dict[str, str]] = {} - with dscpath.open("r") as dscf: - for key, value in debian.deb822.Dsc(dscf).items(): - if key.lower().startswith("checksums-"): - for entry in value: - algo = key[10:].lower() - files.setdefault(entry["name"], dict())[algo] = entry[algo] + for key, value in parse_dsc(dscpath).items(): + if key.lower().startswith("checksums-"): + for entry in value: + algo = key[10:].lower() + files.setdefault(entry["name"], dict())[algo] = entry[algo] for name, checksums in files.items(): download(urllib.parse.urljoin(dscuri, name), checksums, destdir / name) return dscpath @@ -155,11 +159,12 @@ def get_dsc(build: JsonObject) -> typing.Iterator[pathlib.Path]: else: yield pathlib.Path(dscpath) -def get_dsc_files(dscpath: pathlib.Path) -> typing.List[pathlib.Path]: - """Get the component names referenced by the .dsc file.""" - with dscpath.open("r") as dscf: - dsc = debian.deb822.Dsc(dscf) - return [dscpath.parent / item["name"] for item in dsc["Files"]] +def get_dsc_files(dscpath: pathlib.Path, + dscobj: typing.Optional[debian.deb822.Dsc] = None) -> \ + typing.List[pathlib.Path]: + """Get the component names referenced by the .dsc.""" + return [dscpath.parent / item["name"] + for item in (dscobj or parse_dsc(dscpath))["Files"]] def make_option(optname: str, value: typing.Optional[str]) -> typing.List[str]: """Construct a valued option if a value is given.""" -- cgit v1.2.3