X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=buptest.py;h=2089fcf5650330a7353b7b29502cc5a46086a0f2;hb=73f4b83af6c73a0ba48e448883856bf24aacbf7d;hp=dd145eed2d467b0170396849f04f062cebf7b180;hpb=3cb21094f179100881242ff22f6da9a05d04a7fb;p=bup.git diff --git a/buptest.py b/buptest.py index dd145ee..2089fcf 100644 --- a/buptest.py +++ b/buptest.py @@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function from collections import namedtuple from contextlib import contextmanager -from os.path import basename, dirname, realpath +from os.path import abspath, basename, dirname, realpath from pipes import quote from subprocess import PIPE, Popen from traceback import extract_stack @@ -11,6 +11,8 @@ import errno, os, subprocess, sys, tempfile from wvtest import WVPASSEQ, wvfailure_count from bup import helpers +from bup.compat import fsencode, str_type +from bup.io import byte_stream @contextmanager @@ -33,7 +35,7 @@ def no_lingering_errors(): # Assumes (of course) this file is at the top-level of the source tree -_bup_tmp = realpath(dirname(__file__) + '/t/tmp') +_bup_tmp = realpath(dirname(fsencode(__file__))) + b'/t/tmp' try: os.makedirs(_bup_tmp) except OSError as e: @@ -67,15 +69,17 @@ def run(cmd, check=True, input=None, **kwargs): out, err = p.communicate(input=input) if check and p.returncode != 0: raise Exception('subprocess %r failed with status %d%s' - % (' '.join(map(quote, cmd)), p.returncode, + % (cmd, p.returncode, (', stderr: %r' % err) if err else '')) return ex_res(out=out, err=err, proc=p, rc=p.returncode) def logcmd(cmd): - if isinstance(cmd, basestring): - print(cmd, file=sys.stderr) + s = helpers.shstr(cmd) + if isinstance(cmd, str_type): + print(s, file=sys.stderr) else: - print(' '.join(map(quote, cmd)), file=sys.stderr) + # bytes - for now just escape it + print(s.decode(errors='backslashreplace'), file=sys.stderr) def ex(cmd, **kwargs): """Print cmd to stderr and then run it as per ex(...). @@ -85,7 +89,8 @@ def ex(cmd, **kwargs): logcmd(cmd) result = run(cmd, **kwargs) if result.err: - sys.stderr.write(result.err) + sys.stderr.flush() + byte_stream(sys.stderr).write(result.err) return result def exo(cmd, **kwargs):