add --hide-progress, mostly for tests

This commit is contained in:
Brian Warner 2016-02-17 13:19:14 -08:00
parent c5b2800a3e
commit 903129f4a2
4 changed files with 28 additions and 16 deletions

View File

@ -61,7 +61,8 @@ 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 = ProgressPrinter(filesize, args.stdout)
if not args.hide_progress:
p.start()
while received < filesize:
try:
@ -75,7 +76,9 @@ def accept_file(args, them_d, w):
return 1
f.write(plaintext)
received += len(plaintext)
if not args.hide_progress:
p.update(received)
if not args.hide_progress:
p.finish()
assert received == filesize
@ -151,7 +154,8 @@ 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 = ProgressPrinter(filesize, args.stdout)
if not args.hide_progress:
p.start()
while received < filesize:
try:
@ -165,7 +169,9 @@ def accept_directory(args, them_d, w):
return 1
f.write(plaintext)
received += len(plaintext)
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)

View File

@ -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,12 +87,15 @@ 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
if not hide_progress:
p.start()
while sent < filesize:
plaintext = f.read(CHUNKSIZE)
record_pipe.send_record(plaintext)
sent += len(plaintext)
if not hide_progress:
p.update(sent)
if not hide_progress:
p.finish()
print(u"File sent.. waiting for confirmation", file=stdout)

View File

@ -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")

View File

@ -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",
]