summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2022-09-21 12:25:04 +0200
committerHelmut Grohne <helmut@subdivi.de>2022-09-21 12:25:04 +0200
commita6eba58d0c84ae596be527078904447f29622ff1 (patch)
tree570717aa616da679b8140a902bf46eb855190dbd
parent9c163cd20b42d74af67078fcc7ebfe86e0740268 (diff)
downloadmdbp-a6eba58d0c84ae596be527078904447f29622ff1.tar.gz
sbuild: generalize addition of hook commands
-rw-r--r--mdbp/sbuild.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/mdbp/sbuild.py b/mdbp/sbuild.py
index da0ac4b..8330e6e 100644
--- a/mdbp/sbuild.py
+++ b/mdbp/sbuild.py
@@ -40,6 +40,20 @@ def perl_conf(conf: typing.Dict[str, PerlValue]) -> str:
return "".join("$%s=%s;\n" % (key, perl_repr(value))
for key, value in conf.items()) + "1;\n"
+
+def add_external_command(
+ conf: typing.Dict[str, PerlValue], stage: str, command: str
+) -> None:
+ """Modify the given conf object to add the given command on the given
+ external_commands stage.
+ """
+ extcomm = conf.setdefault("external_commands", {})
+ assert isinstance(extcomm, dict)
+ comms = extcomm.setdefault(stage, [])
+ assert isinstance(comms, list)
+ comms.append(command)
+
+
def main() -> None:
"""Entry point for mdbp-sbuild backend"""
parser = argparse.ArgumentParser()
@@ -78,7 +92,7 @@ def main() -> None:
run_lintian=bool(build.get("lintian", {}).get("run")),
extra_repositories=build.get("extra_repositories", []),
build_environment=compute_env(build),
- external_commands={})
+ )
with contextlib.suppress(KeyError):
sbc["lintian_opts"] = build["lintian"]["options"]
with contextlib.suppress(KeyError):
@@ -90,10 +104,16 @@ def main() -> None:
with contextlib.suppress(KeyError):
sbc["build_path"] = build["build_path"]
if build.get("network") == "try-disable":
- sbc["external_commands"]["starting-build-commands"] = \
- ["mv /etc/resolv.conf /etc/resolv.conf.disabled"]
- sbc["external_commands"]["finished-build-commands"] = \
- ["mv /etc/resolv.conf.disabled /etc/resolv.conf"]
+ add_external_command(
+ sbc,
+ "starting-build-commands",
+ "mv /etc/resolv.conf /etc/resolv.conf.disabled",
+ )
+ add_external_command(
+ sbc,
+ "finished-build-commands",
+ "mv /etc/resolv.conf.disabled /etc/resolv.conf",
+ )
with contextlib.ExitStack() as stack:
sbuildconf = stack.enter_context(temporary_static_file(perl_conf(sbc)))