Add some logging after download is finished. NFC (#1413)

Also move some code outside of the `using` block.
This commit is contained in:
Sam Clegg
2024-06-25 13:04:03 -07:00
committed by GitHub
parent a6db8d2872
commit 8caaa25afb

View File

@@ -682,20 +682,21 @@ def download_with_curl(url, file_name):
def download_with_urllib(url, file_name): def download_with_urllib(url, file_name):
u = urlopen(url) u = urlopen(url)
with open(file_name, 'wb') as f: file_size = get_content_length(u)
file_size = get_content_length(u) if file_size > 0:
if file_size > 0: print("Downloading: %s from %s, %s Bytes" % (file_name, url, file_size))
print("Downloading: %s from %s, %s Bytes" % (file_name, url, file_size)) else:
else: print("Downloading: %s from %s" % (file_name, url))
print("Downloading: %s from %s" % (file_name, url))
file_size_dl = 0 file_size_dl = 0
# Draw a progress bar 80 chars wide (in non-TTY mode) # Draw a progress bar 80 chars wide (in non-TTY mode)
progress_max = 80 - 4 progress_max = 80 - 4
progress_shown = 0 progress_shown = 0
block_sz = 256 * 1024 block_sz = 256 * 1024
if not TTY_OUTPUT: if not TTY_OUTPUT:
print(' [', end='') print(' [', end='')
with open(file_name, 'wb') as f:
while True: while True:
buffer = u.read(block_sz) buffer = u.read(block_sz)
if not buffer: if not buffer:
@@ -713,9 +714,12 @@ def download_with_urllib(url, file_name):
print('-', end='') print('-', end='')
sys.stdout.flush() sys.stdout.flush()
progress_shown += 1 progress_shown += 1
if not TTY_OUTPUT:
print(']') if not TTY_OUTPUT:
sys.stdout.flush() print(']')
sys.stdout.flush()
debug_print('finished downloading (%d bytes)' % file_size_dl)
# On success, returns the filename on the disk pointing to the destination file that was produced # On success, returns the filename on the disk pointing to the destination file that was produced