print args so they can be pasted into a terminal

This commit is contained in:
2014-11-20 15:36:26 +01:00
parent 5952043f33
commit c5d86eb45a

View File

@@ -101,9 +101,16 @@ PROJECT_NAME = "test_project"
CURRENT_DIR = os.path.dirname(__file__) CURRENT_DIR = os.path.dirname(__file__)
def args_as_string(args):
""" Print args so we can paste them to run them again.
"""
import shlex
return " ".join([shlex.quote(c) for c in args])
def run(cmd, cwd=None): def run(cmd, cwd=None):
if VERBOSE: if VERBOSE:
print(">>> ", " ".join(cmd)) print(">>> ", args_as_string(cmd))
import subprocess import subprocess
kwargs = dict( kwargs = dict(
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
@@ -131,7 +138,7 @@ def run_check(cmd, cwd=None, returncode_ok=(0,)):
# verbose will have already printed # verbose will have already printed
if not VERBOSE: if not VERBOSE:
print(">>> ", " ".join(cmd)) print(">>> ", args_as_string(cmd))
sys.stdout.write(" stdout: %s\n" % stdout.strip()) sys.stdout.write(" stdout: %s\n" % stdout.strip())
sys.stdout.write(" stderr: %s\n" % stderr.strip()) sys.stdout.write(" stderr: %s\n" % stderr.strip())
sys.stdout.write(" return: %d\n" % returncode) sys.stdout.write(" return: %d\n" % returncode)
@@ -218,7 +225,10 @@ def bam_run(argv, cwd=None):
sys.stdout.write("\n running: ") sys.stdout.write("\n running: ")
if cwd is not None: if cwd is not None:
sys.stdout.write("cd %r ; " % cwd) sys.stdout.write("cd %r ; " % cwd)
sys.stdout.write("bam %s\n" % " ".join(argv)) import shlex
sys.stdout.write("bam %s\n" % " ".join([shlex.quote(c) for c in argv]))
# input('press_key!:') # input('press_key!:')
with StdIO() as fakeio: with StdIO() as fakeio:
@@ -617,7 +627,6 @@ class BamDeleteTest(BamSessionTestCase):
new_session_path = os.path.join(proj_path, "testfile") new_session_path = os.path.join(proj_path, "testfile")
run(["rm", os.path.join(new_session_path, "testfile.txt")]) run(["rm", os.path.join(new_session_path, "testfile.txt")])
stdout, stderr = bam_run(["commit", "-m", "test deletion"], new_session_path) stdout, stderr = bam_run(["commit", "-m", "test deletion"], new_session_path)
wait_for_input()
self.assertEqual("", stderr) self.assertEqual("", stderr)
# check if deletion of the file has happened # check if deletion of the file has happened
d = os.path.join(self.path_local_store, "testfile") d = os.path.join(self.path_local_store, "testfile")