summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2022-09-21 11:53:52 +0200
committerHelmut Grohne <helmut@subdivi.de>2022-09-21 11:53:52 +0200
commit9c163cd20b42d74af67078fcc7ebfe86e0740268 (patch)
tree81e1f8c637550695bdc995d663262428f58fdc34
parenteb8438c0013f8da4ee6b25a8f94d14bfa33a57c4 (diff)
downloadmdbp-9c163cd20b42d74af67078fcc7ebfe86e0740268.tar.gz
pbuilder: generalize hook support code
-rw-r--r--mdbp/pbuilder.py49
1 files changed, 38 insertions, 11 deletions
diff --git a/mdbp/pbuilder.py b/mdbp/pbuilder.py
index 6eba440..e074ed4 100644
--- a/mdbp/pbuilder.py
+++ b/mdbp/pbuilder.py
@@ -27,6 +27,27 @@ def find_basetgz(distribution: str,
return basetgz
raise ValueError("unsupported distribution %s" % distribution)
+
+@contextlib.contextmanager
+def hookdir() -> typing.Iterator[
+ typing.Tuple[pathlib.Path, typing.Callable[[str, str], None]]
+]:
+ """A context manager that returns a pair of a hook directory suitable for
+ pbuilder and a function for adding hooks to the directory.
+ """
+ with tempfile.TemporaryDirectory() as tdir:
+ directory = pathlib.Path(tdir)
+ counter = 0
+
+ def addhook(key: str, content: str, prio: str = "50") -> None:
+ nonlocal counter
+ hookpath = directory / ("%s%s%05X" % (key, prio, counter))
+ hookpath.write_text(content)
+ hookpath.chmod(0o755)
+
+ yield (directory, addhook)
+
+
def main() -> None:
"""Entry point for mdbp-pbuilder backend"""
parser = argparse.ArgumentParser()
@@ -87,24 +108,30 @@ def main() -> None:
"--configfile",
str(stack.enter_context(temporary_static_file(pbuilderrc))),
])
- hookdir = pathlib.Path(
- stack.enter_context(tempfile.TemporaryDirectory()))
- hook = hookdir / "D50aptupdate"
- hook.write_text("""#/bin/sh
+ hookdirname, addhook = stack.enter_context(hookdir())
+ addhook(
+ "D",
+ """#/bin/sh
set -e
apt-get --error-on=any update
%s dist-upgrade
-""" % shlex.join(apt_get))
- hook.chmod(0o755)
+"""
+ % shlex.join(apt_get),
+ )
if build.get("lintian", {}).get("run", False):
- hook = hookdir / "B90lintian"
- hook.write_text("""#!/bin/sh
+ addhook(
+ "B",
+ """#!/bin/sh
set -e
%s install lintian
runuser -u pbuilder -- lintian %s "${BUILDDIR:-/tmp/buildd}"/*.changes
-""" % (shlex.join(apt_get), shlex.join(build["lintian"].get("options", []))))
- hook.chmod(0o755)
- cmd.extend(["--hookdir", str(hookdir), *args.pbuilderopts,
+"""
+ % (
+ shlex.join(apt_get),
+ shlex.join(build["lintian"].get("options", [])),
+ ),
+ )
+ cmd.extend(["--hookdir", str(hookdirname), *args.pbuilderopts,
str(stack.enter_context(get_dsc(build)))])
ret = subprocess.call(cmd, env=compute_env(build),
stdout=None if enablelog