From 3f15a783afa7a62c633cc076e88a5d22731ebd8d Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sun, 12 Jan 2020 11:54:26 -0600 Subject: [PATCH] helpers: add close_fds to exo Add close_fds to exo() for import-duplicity, and while we're there, define readpipe in terms of exo(), since it's just a simplification. Default close_fds to True, since it doesn't look like we need to preserve the open fds in our other calls. Signed-off-by: Rob Browning Tested-by: Rob Browning --- lib/bup/helpers.py | 14 +++++--------- lib/bup/t/thelpers.py | 8 +++----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index a5c5165..cfbdff4 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -317,14 +317,16 @@ def exo(cmd, stderr=None, shell=False, check=True, - preexec_fn=None): + preexec_fn=None, + close_fds=True): if input: assert stdin in (None, PIPE) stdin = PIPE p = Popen(cmd, stdin=stdin, stdout=PIPE, stderr=stderr, shell=shell, - preexec_fn=preexec_fn) + preexec_fn=preexec_fn, + close_fds=close_fds) out, err = p.communicate(input) if check and p.returncode != 0: raise Exception('subprocess %r failed with status %d%s' @@ -334,13 +336,7 @@ def exo(cmd, def readpipe(argv, preexec_fn=None, shell=False): """Run a subprocess and return its output.""" - p = subprocess.Popen(argv, stdout=subprocess.PIPE, preexec_fn=preexec_fn, - shell=shell) - out, err = p.communicate() - if p.returncode != 0: - raise Exception('subprocess %r failed with status %d' - % (b' '.join(argv), p.returncode)) - return out + return exo(argv, preexec_fn=preexec_fn, shell=shell)[0] def _argmax_base(command): diff --git a/lib/bup/t/thelpers.py b/lib/bup/t/thelpers.py index c71cbb7..17ee635 100644 --- a/lib/bup/t/thelpers.py +++ b/lib/bup/t/thelpers.py @@ -133,11 +133,9 @@ def test_readpipe(): try: readpipe([b'bash', b'-c', b'exit 42']) except Exception as ex: - if not re.match("^subprocess b?'bash -c exit 42' failed with status 42$", - str(ex)): - WVPASSEQ(str(ex), - "^subprocess b?'bash -c exit 42' failed with status 42$") - + rx = '^subprocess b?"bash -c \'exit 42\'" failed with status 42$' + if not re.match(rx, str(ex)): + WVPASSEQ(str(ex), rx) @wvtest -- 2.39.2