Skip to content

Commit 8caaa25

Browse files
authored
Add some logging after download is finished. NFC (#1413)
Also move some code outside of the `using` block.
1 parent a6db8d2 commit 8caaa25

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

emsdk.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -682,20 +682,21 @@ def download_with_curl(url, file_name):
682682

683683
def download_with_urllib(url, file_name):
684684
u = urlopen(url)
685+
file_size = get_content_length(u)
686+
if file_size > 0:
687+
print("Downloading: %s from %s, %s Bytes" % (file_name, url, file_size))
688+
else:
689+
print("Downloading: %s from %s" % (file_name, url))
690+
691+
file_size_dl = 0
692+
# Draw a progress bar 80 chars wide (in non-TTY mode)
693+
progress_max = 80 - 4
694+
progress_shown = 0
695+
block_sz = 256 * 1024
696+
if not TTY_OUTPUT:
697+
print(' [', end='')
698+
685699
with open(file_name, 'wb') as f:
686-
file_size = get_content_length(u)
687-
if file_size > 0:
688-
print("Downloading: %s from %s, %s Bytes" % (file_name, url, file_size))
689-
else:
690-
print("Downloading: %s from %s" % (file_name, url))
691-
692-
file_size_dl = 0
693-
# Draw a progress bar 80 chars wide (in non-TTY mode)
694-
progress_max = 80 - 4
695-
progress_shown = 0
696-
block_sz = 256 * 1024
697-
if not TTY_OUTPUT:
698-
print(' [', end='')
699700
while True:
700701
buffer = u.read(block_sz)
701702
if not buffer:
@@ -713,9 +714,12 @@ def download_with_urllib(url, file_name):
713714
print('-', end='')
714715
sys.stdout.flush()
715716
progress_shown += 1
716-
if not TTY_OUTPUT:
717-
print(']')
718-
sys.stdout.flush()
717+
718+
if not TTY_OUTPUT:
719+
print(']')
720+
sys.stdout.flush()
721+
722+
debug_print('finished downloading (%d bytes)' % file_size_dl)
719723

720724

721725
# On success, returns the filename on the disk pointing to the destination file that was produced

0 commit comments

Comments
 (0)