Bug 1234913 - Pre: Show download progress during |mach artifact install|. r?chmanchester draft
authorNick Alexander <nalexander@mozilla.com>
Wed, 24 Feb 2016 23:21:37 -0800
changeset 334423 466f5762380cdd670a1259f3d703a39d6ad51068
parent 334422 e2422dcc22d29a6ac02906c9489c5441e8e949aa
child 334424 847836fdbcaf930894f05c7c555a1ed319c130d7
push id11551
push usernalexander@mozilla.com
push dateThu, 25 Feb 2016 07:47:43 +0000
reviewerschmanchester
bugs1234913
milestone47.0a1
Bug 1234913 - Pre: Show download progress during |mach artifact install|. r?chmanchester 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
@@ -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.