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,
|
label=label,
|
||||||
update_min_steps=min(
|
update_min_steps=min(
|
||||||
256 * 1024, file_size / 100
|
256 * 1024, file_size / 100
|
||||||
), # every 256Kb or less,
|
), # every 256Kb or less
|
||||||
) as pb:
|
) as pb:
|
||||||
for chunk in pb:
|
for chunk in pb:
|
||||||
pb.update(len(chunk))
|
pb.update(len(chunk))
|
||||||
|
@ -61,7 +61,7 @@ class PackageManagerDownloadMixin:
|
|||||||
self.set_download_utime(dl_path)
|
self.set_download_utime(dl_path)
|
||||||
return 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())
|
tmp_fd, tmp_path = tempfile.mkstemp(dir=self.get_download_dir())
|
||||||
try:
|
try:
|
||||||
with LockFile(dl_path):
|
with LockFile(dl_path):
|
||||||
@ -70,7 +70,7 @@ class PackageManagerDownloadMixin:
|
|||||||
fd.set_destination(tmp_path)
|
fd.set_destination(tmp_path)
|
||||||
fd.start(with_progress=with_progress, silent=silent)
|
fd.start(with_progress=with_progress, silent=silent)
|
||||||
except IOError as exc:
|
except IOError as exc:
|
||||||
raise_error = not with_progress
|
raise_error = not silent
|
||||||
if with_progress:
|
if with_progress:
|
||||||
try:
|
try:
|
||||||
fd = FileDownloader(url)
|
fd = FileDownloader(url)
|
||||||
|
@ -20,6 +20,7 @@ from zipfile import ZipFile
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import fs
|
from platformio import fs
|
||||||
|
from platformio.compat import is_terminal
|
||||||
from platformio.package.exception import PackageException
|
from platformio.package.exception import PackageException
|
||||||
|
|
||||||
|
|
||||||
@ -158,18 +159,38 @@ class FileUnpacker:
|
|||||||
|
|
||||||
def unpack(
|
def unpack(
|
||||||
self, dest_dir=None, with_progress=True, check_unpacked=True, silent=False
|
self, dest_dir=None, with_progress=True, check_unpacked=True, silent=False
|
||||||
):
|
): # pylint: disable=too-many-branches
|
||||||
assert self._archiver
|
assert self._archiver
|
||||||
|
label = "Unpacking"
|
||||||
|
items = self._archiver.get_items()
|
||||||
if not dest_dir:
|
if not dest_dir:
|
||||||
dest_dir = os.getcwd()
|
dest_dir = os.getcwd()
|
||||||
|
|
||||||
if not with_progress or silent:
|
if not with_progress or silent:
|
||||||
if not silent:
|
if not silent:
|
||||||
click.echo("Unpacking...")
|
click.echo(f"{label}...")
|
||||||
for item in self._archiver.get_items():
|
for item in items:
|
||||||
self._archiver.extract_item(item, dest_dir)
|
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:
|
else:
|
||||||
items = self._archiver.get_items()
|
with click.progressbar(
|
||||||
with click.progressbar(items, label="Unpacking") as pb:
|
items,
|
||||||
|
label=label,
|
||||||
|
update_min_steps=min(50, len(items) / 100), # every 50 files or less
|
||||||
|
) as pb:
|
||||||
for item in pb:
|
for item in pb:
|
||||||
self._archiver.extract_item(item, dest_dir)
|
self._archiver.extract_item(item, dest_dir)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user