Skip to content

Commit

Permalink
Add progressbar to SuperPMI.py script (#48649)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Feb 23, 2021
1 parent 8a3fd5a commit 2c8f2dc
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/coreclr/scripts/superpmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,17 @@
################################################################################


def download_progress_hook(count, block_size, total_size):
""" A hook for urlretrieve to report download progress
Args:
count (int) : current block index
block_size (int) : size of a block
total_size (int) : total size of a payload
"""
sys.stdout.write("\rDownloading %d/%d..." % (count - 1, total_size / max(block_size, 1)))
sys.stdout.flush()

def is_zero_length_file(fpath):
""" Determine if a file system path refers to an existing file that is zero length
Expand Down Expand Up @@ -1859,7 +1870,7 @@ def determine_coredis_tools(coreclr_args):
os.makedirs(coreclr_args.core_root)
coredistools_uri = az_blob_storage_superpmi_container_uri + "/libcoredistools/{}-{}/{}".format(coreclr_args.host_os.lower(), coreclr_args.arch.lower(), coredistools_dll_name)
logging.info("Download: %s -> %s", coredistools_uri, coredistools_location)
urllib.request.urlretrieve(coredistools_uri, coredistools_location)
urllib.request.urlretrieve(coredistools_uri, coredistools_location, reporthook=download_progress_hook)

assert os.path.isfile(coredistools_location)
return coredistools_location
Expand Down Expand Up @@ -1896,7 +1907,7 @@ def determine_pmi_location(coreclr_args):
else:
pmi_uri = az_blob_storage_superpmi_container_uri + "/pmi/pmi.dll"
logging.info("Download: %s -> %s", pmi_uri, pmi_location)
urllib.request.urlretrieve(pmi_uri, pmi_location)
urllib.request.urlretrieve(pmi_uri, pmi_location, reporthook=download_progress_hook)

assert os.path.isfile(pmi_location)
return pmi_location
Expand Down Expand Up @@ -2350,7 +2361,7 @@ def download_urls(urls, target_dir, verbose=True, fail_if_not_found=True):
try:
if verbose:
logging.info("Download: %s -> %s", url, download_path)
urllib.request.urlretrieve(url, download_path)
urllib.request.urlretrieve(url, download_path, reporthook=download_progress_hook)
except urllib.error.HTTPError as httperror:
if (httperror == 404) and fail_if_not_found:
raise httperror
Expand Down Expand Up @@ -2381,7 +2392,7 @@ def download_urls(urls, target_dir, verbose=True, fail_if_not_found=True):
try:
if verbose:
logging.info("Download: %s -> %s", url, download_path)
urllib.request.urlretrieve(url, download_path)
urllib.request.urlretrieve(url, download_path, reporthook=download_progress_hook)
local_files.append(download_path)
except urllib.error.HTTPError as httperror:
if (httperror == 404) and fail_if_not_found:
Expand Down

0 comments on commit 2c8f2dc

Please sign in to comment.