summaryrefslogtreecommitdiff
path: root/mdbp/pbuilder.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2021-07-06 14:02:29 +0200
committerHelmut Grohne <helmut@subdivi.de>2021-07-06 14:02:29 +0200
commitfa06dfa5575841bb60dd83bc46426f1a7d737b9b (patch)
tree8b6bb5c309fc61584af6dd79fe5c0b031dd429b4 /mdbp/pbuilder.py
parent58e77f47adf737c27e87e185adfe437dfebed6df (diff)
downloadmdbp-fa06dfa5575841bb60dd83bc46426f1a7d737b9b.tar.gz
pbuilder: use an ExitStack
Doing so bears three advantages: * Adding more context managers - especially conditional ones - becomes easier. * Context managers can be delayed until the point where they're actually needed without adding to indentation. * We get rid of two local variables. Less state in your head.
Diffstat (limited to 'mdbp/pbuilder.py')
-rw-r--r--mdbp/pbuilder.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/mdbp/pbuilder.py b/mdbp/pbuilder.py
index fb5c4fe..052dce8 100644
--- a/mdbp/pbuilder.py
+++ b/mdbp/pbuilder.py
@@ -3,6 +3,7 @@
"""mdbp backend using pbuilder"""
import argparse
+import contextlib
import os
import pathlib
import shlex
@@ -78,8 +79,9 @@ def main() -> None:
if not enablelog:
cmd.extend(["--loglevel", "E"])
apt_get = ["apt-get", "-oAPT::Keep-Downloaded-Path=false", "--yes"]
- with tempfile.TemporaryDirectory() as hookdirn, get_dsc(build) as dscpath:
- hookdir = pathlib.Path(hookdirn)
+ with contextlib.ExitStack() as stack:
+ hookdir = pathlib.Path(
+ stack.enter_context(tempfile.TemporaryDirectory()))
hook = hookdir / "D50aptupdate"
hook.write_text("""#/bin/sh
set -e
@@ -95,7 +97,8 @@ set -e
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", hookdirn, *args.pbuilderopts, str(dscpath)])
+ cmd.extend(["--hookdir", str(hookdir), *args.pbuilderopts,
+ str(stack.enter_context(get_dsc(build)))])
ret = subprocess.call(cmd, env=compute_env(build),
stdout=None if enablelog
else subprocess.DEVNULL,