From 903129f4a2a7abf7835f19c42c9f73a0608faf4c Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 17 Feb 2016 13:19:14 -0800 Subject: [PATCH] add --hide-progress, mostly for tests --- src/wormhole/scripts/cmd_receive.py | 22 ++++++++++++++-------- src/wormhole/scripts/cmd_send_blocking.py | 13 ++++++++----- src/wormhole/scripts/runner.py | 2 ++ src/wormhole/test/test_scripts.py | 7 ++++--- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/wormhole/scripts/cmd_receive.py b/src/wormhole/scripts/cmd_receive.py index 12003de..caab1cb 100644 --- a/src/wormhole/scripts/cmd_receive.py +++ b/src/wormhole/scripts/cmd_receive.py @@ -61,8 +61,9 @@ def accept_file(args, them_d, w): tmp = abs_filename + ".tmp" with open(tmp, "wb") as f: received = 0 - p = ProgressPrinter(filesize, sys.stdout) - p.start() + p = ProgressPrinter(filesize, args.stdout) + if not args.hide_progress: + p.start() while received < filesize: try: plaintext = record_pipe.receive_record() @@ -75,8 +76,10 @@ def accept_file(args, them_d, w): return 1 f.write(plaintext) received += len(plaintext) - p.update(received) - p.finish() + if not args.hide_progress: + p.update(received) + if not args.hide_progress: + p.finish() assert received == filesize os.rename(tmp, abs_filename) @@ -151,8 +154,9 @@ def accept_directory(args, them_d, w): (filesize, dirname, transit_receiver.describe()), file=args.stdout) f = tempfile.SpooledTemporaryFile() received = 0 - p = ProgressPrinter(filesize, sys.stdout) - p.start() + p = ProgressPrinter(filesize, args.stdout) + if not args.hide_progress: + p.start() while received < filesize: try: plaintext = record_pipe.receive_record() @@ -165,8 +169,10 @@ def accept_directory(args, them_d, w): return 1 f.write(plaintext) received += len(plaintext) - p.update(received) - p.finish() + if not args.hide_progress: + p.update(received) + if not args.hide_progress: + p.finish() assert received == filesize print(u"Unpacking zipfile..", file=args.stdout) with zipfile.ZipFile(f, "r", zipfile.ZIP_DEFLATED) as zf: diff --git a/src/wormhole/scripts/cmd_send_blocking.py b/src/wormhole/scripts/cmd_send_blocking.py index 90a3bac..a79f8f8 100644 --- a/src/wormhole/scripts/cmd_send_blocking.py +++ b/src/wormhole/scripts/cmd_send_blocking.py @@ -45,7 +45,7 @@ def send_blocking(appid, args, phase1, fd_to_send): raise TransferError("error sending text: %r" % (them_phase1,)) return _send_file_blocking(w, appid, them_phase1, fd_to_send, - transit_sender, args.stdout) + transit_sender, args.stdout, args.hide_progress) def _do_verify(w): verifier = binascii.hexlify(w.get_verifier()).decode("ascii") @@ -60,7 +60,7 @@ def _do_verify(w): raise TransferError("verification rejected, abandoning transfer") def _send_file_blocking(w, appid, them_phase1, fd_to_send, transit_sender, - stdout): + stdout, hide_progress): # we're sending a file, if they accept it @@ -87,13 +87,16 @@ def _send_file_blocking(w, appid, them_phase1, fd_to_send, transit_sender, p = ProgressPrinter(filesize, stdout) with fd_to_send as f: sent = 0 - p.start() + if not hide_progress: + p.start() while sent < filesize: plaintext = f.read(CHUNKSIZE) record_pipe.send_record(plaintext) sent += len(plaintext) - p.update(sent) - p.finish() + if not hide_progress: + p.update(sent) + if not hide_progress: + p.finish() print(u"File sent.. waiting for confirmation", file=stdout) ack = record_pipe.receive_record() diff --git a/src/wormhole/scripts/runner.py b/src/wormhole/scripts/runner.py index 83e584a..278f12f 100644 --- a/src/wormhole/scripts/runner.py +++ b/src/wormhole/scripts/runner.py @@ -27,6 +27,8 @@ g.add_argument("-c", "--code-length", type=int, default=2, metavar="WORDS", help="length of code (in bytes/words)") g.add_argument("-v", "--verify", action="store_true", help="display (and wait for acceptance of) verification string") +g.add_argument("--hide-progress", action="store_true", + help="supress progress-bar display") subparsers = parser.add_subparsers(title="subcommands", dest="subcommand") diff --git a/src/wormhole/test/test_scripts.py b/src/wormhole/test/test_scripts.py index 646cb03..ab723e2 100644 --- a/src/wormhole/test/test_scripts.py +++ b/src/wormhole/test/test_scripts.py @@ -84,17 +84,18 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): def _do_test(self, mode="text", override_filename=False): assert mode in ("text", "file", "directory") wormhole = self.find_executable() - server_args = ["--relay-url", self.relayurl, + common_args = ["--hide-progress", + "--relay-url", self.relayurl, "--transit-helper", ""] code = u"1-abc" message = "test message" - send_args = server_args + [ + send_args = common_args + [ "send", "--code", code, ] - receive_args = server_args + [ + receive_args = common_args + [ "receive", ]