add --hide-progress, mostly for tests
This commit is contained in:
parent
c5b2800a3e
commit
903129f4a2
|
@ -61,8 +61,9 @@ def accept_file(args, them_d, w):
|
||||||
tmp = abs_filename + ".tmp"
|
tmp = abs_filename + ".tmp"
|
||||||
with open(tmp, "wb") as f:
|
with open(tmp, "wb") as f:
|
||||||
received = 0
|
received = 0
|
||||||
p = ProgressPrinter(filesize, sys.stdout)
|
p = ProgressPrinter(filesize, args.stdout)
|
||||||
p.start()
|
if not args.hide_progress:
|
||||||
|
p.start()
|
||||||
while received < filesize:
|
while received < filesize:
|
||||||
try:
|
try:
|
||||||
plaintext = record_pipe.receive_record()
|
plaintext = record_pipe.receive_record()
|
||||||
|
@ -75,8 +76,10 @@ def accept_file(args, them_d, w):
|
||||||
return 1
|
return 1
|
||||||
f.write(plaintext)
|
f.write(plaintext)
|
||||||
received += len(plaintext)
|
received += len(plaintext)
|
||||||
p.update(received)
|
if not args.hide_progress:
|
||||||
p.finish()
|
p.update(received)
|
||||||
|
if not args.hide_progress:
|
||||||
|
p.finish()
|
||||||
assert received == filesize
|
assert received == filesize
|
||||||
|
|
||||||
os.rename(tmp, abs_filename)
|
os.rename(tmp, abs_filename)
|
||||||
|
@ -151,8 +154,9 @@ def accept_directory(args, them_d, w):
|
||||||
(filesize, dirname, transit_receiver.describe()), file=args.stdout)
|
(filesize, dirname, transit_receiver.describe()), file=args.stdout)
|
||||||
f = tempfile.SpooledTemporaryFile()
|
f = tempfile.SpooledTemporaryFile()
|
||||||
received = 0
|
received = 0
|
||||||
p = ProgressPrinter(filesize, sys.stdout)
|
p = ProgressPrinter(filesize, args.stdout)
|
||||||
p.start()
|
if not args.hide_progress:
|
||||||
|
p.start()
|
||||||
while received < filesize:
|
while received < filesize:
|
||||||
try:
|
try:
|
||||||
plaintext = record_pipe.receive_record()
|
plaintext = record_pipe.receive_record()
|
||||||
|
@ -165,8 +169,10 @@ def accept_directory(args, them_d, w):
|
||||||
return 1
|
return 1
|
||||||
f.write(plaintext)
|
f.write(plaintext)
|
||||||
received += len(plaintext)
|
received += len(plaintext)
|
||||||
p.update(received)
|
if not args.hide_progress:
|
||||||
p.finish()
|
p.update(received)
|
||||||
|
if not args.hide_progress:
|
||||||
|
p.finish()
|
||||||
assert received == filesize
|
assert received == filesize
|
||||||
print(u"Unpacking zipfile..", file=args.stdout)
|
print(u"Unpacking zipfile..", file=args.stdout)
|
||||||
with zipfile.ZipFile(f, "r", zipfile.ZIP_DEFLATED) as zf:
|
with zipfile.ZipFile(f, "r", zipfile.ZIP_DEFLATED) as zf:
|
||||||
|
|
|
@ -45,7 +45,7 @@ def send_blocking(appid, args, phase1, fd_to_send):
|
||||||
raise TransferError("error sending text: %r" % (them_phase1,))
|
raise TransferError("error sending text: %r" % (them_phase1,))
|
||||||
|
|
||||||
return _send_file_blocking(w, appid, them_phase1, fd_to_send,
|
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):
|
def _do_verify(w):
|
||||||
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
|
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
|
||||||
|
@ -60,7 +60,7 @@ def _do_verify(w):
|
||||||
raise TransferError("verification rejected, abandoning transfer")
|
raise TransferError("verification rejected, abandoning transfer")
|
||||||
|
|
||||||
def _send_file_blocking(w, appid, them_phase1, fd_to_send, transit_sender,
|
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
|
# 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)
|
p = ProgressPrinter(filesize, stdout)
|
||||||
with fd_to_send as f:
|
with fd_to_send as f:
|
||||||
sent = 0
|
sent = 0
|
||||||
p.start()
|
if not hide_progress:
|
||||||
|
p.start()
|
||||||
while sent < filesize:
|
while sent < filesize:
|
||||||
plaintext = f.read(CHUNKSIZE)
|
plaintext = f.read(CHUNKSIZE)
|
||||||
record_pipe.send_record(plaintext)
|
record_pipe.send_record(plaintext)
|
||||||
sent += len(plaintext)
|
sent += len(plaintext)
|
||||||
p.update(sent)
|
if not hide_progress:
|
||||||
p.finish()
|
p.update(sent)
|
||||||
|
if not hide_progress:
|
||||||
|
p.finish()
|
||||||
|
|
||||||
print(u"File sent.. waiting for confirmation", file=stdout)
|
print(u"File sent.. waiting for confirmation", file=stdout)
|
||||||
ack = record_pipe.receive_record()
|
ack = record_pipe.receive_record()
|
||||||
|
|
|
@ -27,6 +27,8 @@ g.add_argument("-c", "--code-length", type=int, default=2,
|
||||||
metavar="WORDS", help="length of code (in bytes/words)")
|
metavar="WORDS", help="length of code (in bytes/words)")
|
||||||
g.add_argument("-v", "--verify", action="store_true",
|
g.add_argument("-v", "--verify", action="store_true",
|
||||||
help="display (and wait for acceptance of) verification string")
|
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",
|
subparsers = parser.add_subparsers(title="subcommands",
|
||||||
dest="subcommand")
|
dest="subcommand")
|
||||||
|
|
||||||
|
|
|
@ -84,17 +84,18 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
|
||||||
def _do_test(self, mode="text", override_filename=False):
|
def _do_test(self, mode="text", override_filename=False):
|
||||||
assert mode in ("text", "file", "directory")
|
assert mode in ("text", "file", "directory")
|
||||||
wormhole = self.find_executable()
|
wormhole = self.find_executable()
|
||||||
server_args = ["--relay-url", self.relayurl,
|
common_args = ["--hide-progress",
|
||||||
|
"--relay-url", self.relayurl,
|
||||||
"--transit-helper", ""]
|
"--transit-helper", ""]
|
||||||
code = u"1-abc"
|
code = u"1-abc"
|
||||||
message = "test message"
|
message = "test message"
|
||||||
|
|
||||||
send_args = server_args + [
|
send_args = common_args + [
|
||||||
"send",
|
"send",
|
||||||
"--code", code,
|
"--code", code,
|
||||||
]
|
]
|
||||||
|
|
||||||
receive_args = server_args + [
|
receive_args = common_args + [
|
||||||
"receive",
|
"receive",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user