summaryrefslogtreecommitdiff
path: root/mdbp/common.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2021-05-18 15:43:14 +0200
committerHelmut Grohne <helmut@subdivi.de>2021-05-18 15:43:14 +0200
commitb6f54633e5b4cafa851fdec80e8e982d46109be3 (patch)
tree7fe4160b95cf0306d2205c87f6057c849641e04e /mdbp/common.py
parentbdad82ad139c3bedb72d8731dade37a04fdbe11c (diff)
downloadmdbp-b6f54633e5b4cafa851fdec80e8e982d46109be3.tar.gz
mmdebstrap: reimplement build hook recursively
Instead of writing a complex shell script in a limited sub-language of shell, call out to ourselves and implement the build functionality in Python.
Diffstat (limited to 'mdbp/common.py')
-rw-r--r--mdbp/common.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/mdbp/common.py b/mdbp/common.py
index 830aad7..eccefc1 100644
--- a/mdbp/common.py
+++ b/mdbp/common.py
@@ -119,6 +119,27 @@ def download(uri: str, checksums: typing.Dict[str, str],
dest.unlink()
raise
+def download_dsc(buildinput: JsonObject,
+ destdir: pathlib.Path) -> pathlib.Path:
+ """Download the .input.dscuri including referenced components to the given
+ destination directory and return the path to the contained .dsc file.
+ """
+ dscuri = buildinput["dscuri"]
+ dscpath = destdir / dscuri.split("/")[-1]
+ # mypy doesn't grok this:
+ 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 name, checksums in files.items():
+ download(urllib.parse.urljoin(dscuri, name), checksums, destdir / name)
+ return dscpath
+
@contextlib.contextmanager
def get_dsc(build: JsonObject) -> typing.Iterator[pathlib.Path]:
"""A context manager that provides a path pointing at the .dsc file for the
@@ -129,23 +150,8 @@ def get_dsc(build: JsonObject) -> typing.Iterator[pathlib.Path]:
try:
dscpath = build["input"]["dscpath"]
except KeyError:
- dscuri = build["input"]["dscuri"]
- with tempfile.TemporaryDirectory() as tdirname:
- tdir = pathlib.Path(tdirname)
- dscpath = tdir / dscuri.split("/")[-1]
- download(dscuri, build["input"].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 name, checksums in files.items():
- download(urllib.parse.urljoin(dscuri, name), checksums,
- tdir / name)
- yield dscpath
+ with tempfile.TemporaryDirectory() as tdir:
+ yield download_dsc(build["input"], pathlib.Path(tdir))
else:
yield pathlib.Path(dscpath)