]> arthur.barton.de Git - bup.git/commitdiff
Move exc, exo, and logcmd to buptest.py
authorRob Browning <rlb@defaultvalue.org>
Sun, 26 Nov 2017 20:02:49 +0000 (14:02 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sun, 24 Dec 2017 20:28:18 +0000 (14:28 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
buptest.py
t/test-prune-older

index 78e5bb9a83d8b9114e2e84eff1192cf2396c7a07..135713e104c2f845961fd77eb6f19177f4f657d7 100644 (file)
@@ -1,6 +1,9 @@
 
+from __future__ import print_function
 from contextlib import contextmanager
 from os.path import basename, dirname, realpath
+from pipes import quote
+from subprocess import PIPE, Popen, check_call
 from traceback import extract_stack
 import subprocess, sys, tempfile
 
@@ -16,10 +19,10 @@ def no_lingering_errors():
             bt = extract_stack()
             src_file, src_line, src_func, src_txt = bt[-4]
             msg = 'saved_errors ' + repr(helpers.saved_errors)
-            print '! %-70s %s' % ('%s:%-4d %s' % (basename(src_file),
+            print('! %-70s %s' % ('%s:%-4d %s' % (basename(src_file),
                                                   src_line,
                                                   msg),
-                                  'FAILED')
+                                  'FAILED'))
             sys.stdout.flush()
     fail_if_errors()
     helpers.clear_errors()
@@ -41,3 +44,27 @@ def test_tempdir(prefix):
     if wvfailure_count() == initial_failures:
         subprocess.call(['chmod', '-R', 'u+rwX', tmpdir])
         subprocess.call(['rm', '-rf', tmpdir])
+
+
+def logcmd(cmd):
+    if isinstance(cmd, basestring):
+        print(cmd, file=sys.stderr)
+    else:
+        print(' '.join(map(quote, cmd)), file=sys.stderr)
+
+def exc(cmd, shell=False):
+    logcmd(cmd)
+    check_call(cmd, shell=shell)
+
+def exo(cmd, stdin=None, stdout=True, stderr=False, shell=False, check=True):
+    logcmd(cmd)
+    p = Popen(cmd,
+              stdin=None,
+              stdout=(PIPE if stdout else None),
+              stderr=PIPE,
+              shell=shell)
+    out, err = p.communicate()
+    if check and p.returncode != 0:
+        raise Exception('subprocess %r failed with status %d, stderr: %r'
+                        % (' '.join(map(quote, cmd)), p.returncode, err))
+    return out, err, p
index 4ebc94cabf0e4771a563f05f8c240ceb7372e848..9e9d359b7568b707b5c9de366da2c56d3a4ec8da 100755 (executable)
@@ -11,10 +11,8 @@ from difflib import unified_diff
 from itertools import chain, dropwhile, groupby, takewhile
 from os import environ, chdir
 from os.path import abspath, dirname
-from pipes import quote
 from random import choice, randint
 from shutil import copytree, rmtree
-from subprocess import PIPE, Popen, check_call
 from sys import stderr
 from time import localtime, strftime, time
 import os, random, sys
@@ -24,35 +22,12 @@ sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]
 top = os.getcwd()
 bup_cmd = top + '/bup'
 
-from buptest import test_tempdir
+from buptest import exc, exo, test_tempdir
 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
 
 from bup.helpers import partition, period_as_secs, readpipe
 
 
-def logcmd(cmd):
-    if isinstance(cmd, basestring):
-        print(cmd, file=stderr)
-    else:
-        print(' '.join(map(quote, cmd)), file=stderr)
-
-def exc(cmd, shell=False):
-    logcmd(cmd)
-    check_call(cmd, shell=shell)
-
-def exo(cmd, stdin=None, stdout=True, stderr=False, shell=False, check=True):
-    logcmd(cmd)
-    p = Popen(cmd,
-              stdin=None,
-              stdout=(PIPE if stdout else None),
-              stderr=PIPE,
-              shell=shell)
-    out, err = p.communicate()
-    if check and p.returncode != 0:
-        raise Exception('subprocess %r failed with status %d, stderr: %r'
-                        % (' '.join(map(quote, cmd)), p.returncode, err))
-    return out, err, p
-
 def bup(*args):
     return exo((bup_cmd,) + args)[0]