From 9b1f99b994481e78f9c302d4368f6a8266197fad Mon Sep 17 00:00:00 2001 From: David Harrigan Date: Thu, 14 Dec 2017 11:06:27 +0000 Subject: [PATCH 1/3] Change the send command output to help copy and pasting to others A tiny update to show the command to execute along with the code required on the same line, rather than split across two lines. This small change helps when sending the information to others using copy and paste. Fixes #266 -=david=- --- src/wormhole/cli/cmd_send.py | 8 ++++---- src/wormhole/test/test_cli.py | 32 +++++++++++++++----------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index bbba2ce..456c9aa 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -100,9 +100,6 @@ class Sender: args.code = u"0-" other_cmd += " -0" - print(u"On the other computer, please run: %s" % other_cmd, - file=args.stderr) - if args.code: w.set_code(args.code) else: @@ -111,9 +108,12 @@ class Sender: code = yield w.get_code() if not args.zeromode: print(u"Wormhole code is: %s" % code, file=args.stderr) + print(u"On the other computer, please run:", file=args.stderr) + print(u"", file=args.stderr) + print(u"%s %s" % (other_cmd, code), file=args.stderr) + print(u"", file=args.stderr) # flush stderr so the code is displayed immediately args.stderr.flush() - print(u"", file=args.stderr) # We don't print a "waiting" message for get_unverified_key() here, # even though we do that in cmd_receive.py, because it's not at all diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index 6b0265c..a42899c 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -589,9 +589,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): # check sender if mode == "text" or mode == "slow-text": expected = ("Sending text message ({bytes:d} Bytes){NL}" - "On the other computer, please run: " - "wormhole receive{NL}" - "Wormhole code is: {code}{NL}{NL}" + "Wormhole code is: {code}{NL}" + "On the other computer, please run:{NL}{NL}" + "wormhole receive {code}{NL}{NL}" "{KE}" "text message sent{NL}").format(bytes=len(message), code=send_cfg.code, @@ -603,9 +603,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): .format(size=naturalsize(len(message)), name=send_filename, NL=NL), send_stderr) - self.failUnlessIn(u"On the other computer, please run: " - "wormhole receive{NL}" - "Wormhole code is: {code}{NL}{NL}" + self.failUnlessIn(u"Wormhole code is: {code}{NL}" + "On the other computer, please run:{NL}{NL}" + "wormhole receive {code}{NL}{NL}" .format(code=send_cfg.code, NL=NL), send_stderr) self.failUnlessIn(u"File sent.. waiting for confirmation{NL}" @@ -614,9 +614,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): elif mode == "directory": self.failUnlessIn(u"Sending directory", send_stderr) self.failUnlessIn(u"named 'testdir'", send_stderr) - self.failUnlessIn(u"On the other computer, please run: " - "wormhole receive{NL}" - "Wormhole code is: {code}{NL}{NL}" + self.failUnlessIn(u"Wormhole code is: {code}{NL}" + "On the other computer, please run:{NL}{NL}" + "wormhole receive {code}{NL}{NL}" .format(code=send_cfg.code, NL=NL), send_stderr) self.failUnlessIn(u"File sent.. waiting for confirmation{NL}" "Confirmation received. Transfer complete.{NL}" @@ -788,9 +788,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): .format(size=naturalsize(size), name=send_filename, NL=NL), send_stderr) - self.failUnlessIn("On the other computer, please run: " - "wormhole receive{NL}" - "Wormhole code is: {code}{NL}{NL}" + self.failUnlessIn("Wormhole code is: {code}{NL}" + "On the other computer, please run:{NL}{NL}" + "wormhole receive {code}{NL}" .format(code=send_cfg.code, NL=NL), send_stderr) self.failIfIn("File sent.. waiting for confirmation{NL}" @@ -799,9 +799,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): elif mode == "directory": self.failUnlessIn("Sending directory", send_stderr) self.failUnlessIn("named 'testdir'", send_stderr) - self.failUnlessIn("On the other computer, please run: " - "wormhole receive{NL}" - "Wormhole code is: {code}{NL}{NL}" + self.failUnlessIn("Wormhole code is: {code}{NL}" + "On the other computer, please run:{NL}{NL}" + "wormhole receive {code}{NL}" .format(code=send_cfg.code, NL=NL), send_stderr) self.failIfIn("File sent.. waiting for confirmation{NL}" "Confirmation received. Transfer complete.{NL}" @@ -893,8 +893,6 @@ class ZeroMode(ServerBase, unittest.TestCase): # check sender expected = ("Sending text message ({bytes:d} Bytes){NL}" - "On the other computer, please run: " - "wormhole receive -0{NL}{NL}" "text message sent{NL}").format(bytes=len(message), code=send_cfg.code, NL=NL) From c7c7c0381c36c58693a37cd27a0a5bc28ff6a32f Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 19 Dec 2017 12:54:16 -0800 Subject: [PATCH 2/3] update -0 and --text output too --- src/wormhole/cli/cmd_send.py | 19 ++++++++++--------- src/wormhole/test/test_cli.py | 4 ++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index 456c9aa..adec1e2 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -92,13 +92,13 @@ class Sender: offer, self._fd_to_send = self._build_offer() args = self._args - other_cmd = "wormhole receive" + other_cmd = u"wormhole receive" if args.verify: - other_cmd = "wormhole receive --verify" + other_cmd = u"wormhole receive --verify" if args.zeromode: assert not args.code args.code = u"0-" - other_cmd += " -0" + other_cmd += u" -0" if args.code: w.set_code(args.code) @@ -108,12 +108,13 @@ class Sender: code = yield w.get_code() if not args.zeromode: print(u"Wormhole code is: %s" % code, file=args.stderr) - print(u"On the other computer, please run:", file=args.stderr) - print(u"", file=args.stderr) - print(u"%s %s" % (other_cmd, code), file=args.stderr) - print(u"", file=args.stderr) - # flush stderr so the code is displayed immediately - args.stderr.flush() + other_cmd += u" " + code + print(u"On the other computer, please run:", file=args.stderr) + print(u"", file=args.stderr) + print(other_cmd, file=args.stderr) + print(u"", file=args.stderr) + # flush stderr so the code is displayed immediately + args.stderr.flush() # We don't print a "waiting" message for get_unverified_key() here, # even though we do that in cmd_receive.py, because it's not at all diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index a42899c..4fe6c42 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -893,6 +893,10 @@ class ZeroMode(ServerBase, unittest.TestCase): # check sender expected = ("Sending text message ({bytes:d} Bytes){NL}" + "On the other computer, please run:{NL}" + "{NL}" + "wormhole receive -0{NL}" + "{NL}" "text message sent{NL}").format(bytes=len(message), code=send_cfg.code, NL=NL) From 67253bde5515d701ab9a13767cfbfa9695b3a2c2 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 19 Dec 2017 13:41:05 -0800 Subject: [PATCH 3/3] test_cli: make timers more reliable A slow Travis-CI host caused one the 1.0s KEY_TIMER to fire by accident, making the test fail because it wasn't expecting to see the "please be patient" message. Fixed this by increasing the timeout to a very large value when we aren't explicitly testing it. --- src/wormhole/test/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index 4fe6c42..ca2d405 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -530,7 +530,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): ) as mrx_tm: receive_d = cmd_receive.receive(recv_cfg) else: - KEY_TIMER = 0 if mode == "slow-sender-text" else 1.0 + KEY_TIMER = 0 if mode == "slow-sender-text" else 99999 rxw = [] with mock.patch.object(cmd_receive, "KEY_TIMER", KEY_TIMER): send_d = cmd_send.send(send_cfg) @@ -544,7 +544,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): # The sender might fail, leaving the receiver hanging, or vice # versa. Make sure we don't wait on one side exclusively - VERIFY_TIMER = 0 if mode == "slow-text" else 1.0 + VERIFY_TIMER = 0 if mode == "slow-text" else 99999 with mock.patch.object(cmd_receive, "VERIFY_TIMER", VERIFY_TIMER): with mock.patch.object(cmd_send, "VERIFY_TIMER", VERIFY_TIMER): if mock_accept: