Bug 1234913 - Pre: Show download progress during |mach artifact install|. r?chmanchester
Hotel WiFi inspires many things.
MozReview-Commit-ID: 8WoHMWGNf0K
--- a/python/mozbuild/mozbuild/artifacts.py
+++ b/python/mozbuild/mozbuild/artifacts.py
@@ -634,16 +634,31 @@ class ArtifactCache(CacheManager):
'Skipping cache: removing cached downloaded artifact {path}')
os.remove(path)
self.log(logging.INFO, 'artifact',
{'path': path},
'Downloading to temporary location {path}')
try:
dl = self._download_manager.download(url, fname)
+
+ # Python doesn't make it easy to capture a variable outside of the
+ # function scope. last[0] is our last printed value.
+ last = [-1]
+ def download_progress(dl, bytes_so_far, total_size):
+ percent = (float(bytes_so_far) / total_size) * 100
+ now = int(percent / 5)
+ if now == last[0]:
+ return
+ last[0] = now
+ self.log(logging.DEBUG, 'artifact',
+ {'bytes_so_far': bytes_so_far, 'total_size': total_size, 'percent': percent},
+ 'Downloading... {percent:02.1f}')
+ dl.set_progress(download_progress)
+
if dl:
dl.wait()
self.log(logging.INFO, 'artifact',
{'path': os.path.abspath(mozpath.join(self._cache_dir, fname))},
'Downloaded artifact to {path}')
return os.path.abspath(mozpath.join(self._cache_dir, fname))
finally:
# Cancel any background downloads in progress.