Bug 1234913 - Pre: Show download progress during |mach artifact install|. r=nalexander draft
authorNick Alexander <nalexander@mozilla.com>
Wed, 24 Feb 2016 23:21:37 -0800
changeset 335865 c5cef889adb213aa7dac192846ac476fdcce1a5d
parent 335864 3c0b4c656ac51d038248a388e82a1ef7d3680ab1
child 335866 fbbcbf9ec27d0fa8391f2cb6485f826f67ceaa48
push id11896
push usercmanchester@mozilla.com
push dateTue, 01 Mar 2016 19:15:58 +0000
reviewersnalexander
bugs1234913
milestone47.0a1
Bug 1234913 - Pre: Show download progress during |mach artifact install|. r=nalexander Hotel WiFi inspires many things. MozReview-Commit-ID: 8WoHMWGNf0K
python/mozbuild/mozbuild/artifacts.py
--- a/python/mozbuild/mozbuild/artifacts.py
+++ b/python/mozbuild/mozbuild/artifacts.py
@@ -594,16 +594,17 @@ class ArtifactCache(CacheManager):
     def __init__(self, cache_dir, log=None, skip_cache=False):
         # TODO: instead of storing N artifact packages, store M megabytes.
         CacheManager.__init__(self, cache_dir, 'fetch', MAX_CACHED_ARTIFACTS, cache_callback=self.delete_file, log=log, skip_cache=skip_cache)
         self._cache_dir = cache_dir
         size_limit = 1024 * 1024 * 1024 # 1Gb in bytes.
         file_limit = 4 # But always keep at least 4 old artifacts around.
         persist_limit = PersistLimit(size_limit, file_limit)
         self._download_manager = DownloadManager(self._cache_dir, persist_limit=persist_limit)
+        self._last_dl_update = -1
 
     def delete_file(self, key, value):
         try:
             os.remove(value)
             self.log(logging.INFO, 'artifact',
                 {'filename': value},
                 'Purged artifact {filename}')
         except (OSError, IOError):
@@ -634,17 +635,29 @@ 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)
+
+            def download_progress(dl, bytes_so_far, total_size):
+                percent = (float(bytes_so_far) / total_size) * 100
+                now = int(percent / 5)
+                if now == self._last_dl_update:
+                    return
+                self._last_dl_update = now
+                self.log(logging.DEBUG, 'artifact',
+                         {'bytes_so_far': bytes_so_far, 'total_size': total_size, 'percent': percent},
+                         'Downloading... {percent:02.1f} %')
+
             if dl:
+                dl.set_progress(download_progress)
                 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.
             self._download_manager.cancel()