mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-20 12:34:23 -04:00
suppress download progress output to stdout in OSX (fixes #203)
This commit is contained in:
parent
e6db3c27e4
commit
ba424fa427
1 changed files with 12 additions and 6 deletions
|
@ -146,13 +146,13 @@ def download(slug_candidate):
|
||||||
basename = os.path.basename(zip_filename)
|
basename = os.path.basename(zip_filename)
|
||||||
|
|
||||||
def generate():
|
def generate():
|
||||||
chunk_size = 102400 # 100kb
|
chunk_size = 102400 # 100kb
|
||||||
|
|
||||||
fp = open(zip_filename, 'rb')
|
fp = open(zip_filename, 'rb')
|
||||||
done = False
|
done = False
|
||||||
canceled = False
|
canceled = False
|
||||||
while not done:
|
while not done:
|
||||||
chunk = fp.read(102400)
|
chunk = fp.read(chunk_size)
|
||||||
if chunk == '':
|
if chunk == '':
|
||||||
done = True
|
done = True
|
||||||
else:
|
else:
|
||||||
|
@ -162,9 +162,13 @@ def download(slug_candidate):
|
||||||
# tell GUI the progress
|
# tell GUI the progress
|
||||||
downloaded_bytes = fp.tell()
|
downloaded_bytes = fp.tell()
|
||||||
percent = (1.0 * downloaded_bytes / zip_filesize) * 100
|
percent = (1.0 * downloaded_bytes / zip_filesize) * 100
|
||||||
sys.stdout.write(
|
|
||||||
"\r{0:s}, {1:.2f}% ".format(helpers.human_readable_filesize(downloaded_bytes), percent))
|
# suppress stdout platform on OSX (#203)
|
||||||
sys.stdout.flush()
|
if helpers.get_platform() != 'Darwin':
|
||||||
|
sys.stdout.write(
|
||||||
|
"\r{0:s}, {1:.2f}% ".format(helpers.human_readable_filesize(downloaded_bytes), percent))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
add_request(REQUEST_PROGRESS, path, {'id': download_id, 'bytes': downloaded_bytes})
|
add_request(REQUEST_PROGRESS, path, {'id': download_id, 'bytes': downloaded_bytes})
|
||||||
except:
|
except:
|
||||||
# looks like the download was canceled
|
# looks like the download was canceled
|
||||||
|
@ -175,7 +179,9 @@ def download(slug_candidate):
|
||||||
add_request(REQUEST_CANCELED, path, {'id': download_id})
|
add_request(REQUEST_CANCELED, path, {'id': download_id})
|
||||||
|
|
||||||
fp.close()
|
fp.close()
|
||||||
sys.stdout.write("\n")
|
|
||||||
|
if helpers.get_platform() != 'Darwin':
|
||||||
|
sys.stdout.write("\n")
|
||||||
|
|
||||||
# download is finished, close the server
|
# download is finished, close the server
|
||||||
if not stay_open and not canceled:
|
if not stay_open and not canceled:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue