forked from platformio/platformio-core
Provide verbose unpacking in non-terminal mode
This commit is contained in:
2
docs
2
docs
Submodule docs updated: 6647f6e074...437b1175bd
@ -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))
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user