diff --git a/docs b/docs index 6647f6e0..437b1175 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 6647f6e074168012e48e21666db6bd7a1df33130 +Subproject commit 437b1175bdb310e143f1fe6312433ba4f34ef715 diff --git a/platformio/package/download.py b/platformio/package/download.py index 5045e856..17cc1f30 100644 --- a/platformio/package/download.py +++ b/platformio/package/download.py @@ -105,7 +105,7 @@ class FileDownloader: label=label, update_min_steps=min( 256 * 1024, file_size / 100 - ), # every 256Kb or less, + ), # every 256Kb or less ) as pb: for chunk in pb: pb.update(len(chunk)) diff --git a/platformio/package/manager/_download.py b/platformio/package/manager/_download.py index d1ffe710..bf844980 100644 --- a/platformio/package/manager/_download.py +++ b/platformio/package/manager/_download.py @@ -61,7 +61,7 @@ class PackageManagerDownloadMixin: self.set_download_utime(dl_path) return dl_path - with_progress = not silent and not app.is_disabled_progressbar() + with_progress = not app.is_disabled_progressbar() tmp_fd, tmp_path = tempfile.mkstemp(dir=self.get_download_dir()) try: with LockFile(dl_path): @@ -70,7 +70,7 @@ class PackageManagerDownloadMixin: fd.set_destination(tmp_path) fd.start(with_progress=with_progress, silent=silent) except IOError as exc: - raise_error = not with_progress + raise_error = not silent if with_progress: try: fd = FileDownloader(url) diff --git a/platformio/package/unpack.py b/platformio/package/unpack.py index 35e0da68..9d8919c3 100644 --- a/platformio/package/unpack.py +++ b/platformio/package/unpack.py @@ -20,6 +20,7 @@ from zipfile import ZipFile import click from platformio import fs +from platformio.compat import is_terminal from platformio.package.exception import PackageException @@ -158,18 +159,38 @@ class FileUnpacker: def unpack( self, dest_dir=None, with_progress=True, check_unpacked=True, silent=False - ): + ): # pylint: disable=too-many-branches assert self._archiver + label = "Unpacking" + items = self._archiver.get_items() if not dest_dir: dest_dir = os.getcwd() + if not with_progress or silent: if not silent: - click.echo("Unpacking...") - for item in self._archiver.get_items(): + click.echo(f"{label}...") + for item in items: self._archiver.extract_item(item, dest_dir) + elif not is_terminal(): + click.echo(f"{label} 0%", nl=False) + print_percent_step = 10 + printed_percents = 0 + unpacked_nums = 0 + for item in items: + self._archiver.extract_item(item, dest_dir) + unpacked_nums += 1 + if (unpacked_nums / len(items) * 100) >= ( + printed_percents + print_percent_step + ): + printed_percents += print_percent_step + click.echo(f" {printed_percents}%", nl=False) + click.echo("") else: - items = self._archiver.get_items() - with click.progressbar(items, label="Unpacking") as pb: + with click.progressbar( + items, + label=label, + update_min_steps=min(50, len(items) / 100), # every 50 files or less + ) as pb: for item in pb: self._archiver.extract_item(item, dest_dir)