reformat dynamic_progress.py example with Black

This commit is contained in:
Kenneth Hoste 2021-09-19 09:49:04 +02:00
parent c875b9c834
commit 5ecd4ad774
No known key found for this signature in database
GPG Key ID: 90C14B582D70E3BE
1 changed files with 21 additions and 12 deletions

View File

@ -10,7 +10,13 @@ import time
from rich.console import RenderGroup
from rich.live import Live
from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn, TimeElapsedColumn
from rich.progress import (
BarColumn,
Progress,
SpinnerColumn,
TextColumn,
TimeElapsedColumn,
)
def run_steps(name, step_times, app_steps_task_id):
@ -50,23 +56,20 @@ step_progress = Progress(
)
# progress bar for current app (progress in steps)
app_steps_progress = Progress(
TextColumn("[bold blue]Progress for app {task.fields[name]}: {task.percentage:.0f}%"),
TextColumn(
"[bold blue]Progress for app {task.fields[name]}: {task.percentage:.0f}%"
),
BarColumn(),
TextColumn("({task.completed} of {task.total} steps done)"),
)
# overall progress bar
overall_progress = Progress(
TimeElapsedColumn(),
BarColumn(),
TextColumn("{task.description}")
TimeElapsedColumn(), BarColumn(), TextColumn("{task.description}")
)
# group of progress bars;
# some are always visible, others will disappear when progress is complete
group = RenderGroup(
current_app_progress,
step_progress,
app_steps_progress,
overall_progress
current_app_progress, step_progress, app_steps_progress, overall_progress
)
# tuple specifies how long each step takes for that app
@ -92,16 +95,22 @@ with Live(group):
# add progress bar for steps of this app, and run the steps
current_task_id = current_app_progress.add_task("Installing app %s" % name)
app_steps_task_id = app_steps_progress.add_task("", total=len(step_times), name=name)
app_steps_task_id = app_steps_progress.add_task(
"", total=len(step_times), name=name
)
run_steps(name, step_times, app_steps_task_id)
# stop and hide steps progress bar for this specific app
app_steps_progress.update(app_steps_task_id, visible=False)
current_app_progress.stop_task(current_task_id)
current_app_progress.update(current_task_id, description="[bold green]App %s installed!" % name)
current_app_progress.update(
current_task_id, description="[bold green]App %s installed!" % name
)
# increase overall progress now this task is done
overall_progress.update(overall_task_id, advance=1)
# final update for message on overall progress bar
overall_progress.update(overall_task_id, description="[bold green]%s apps installed, done!" % len(apps))
overall_progress.update(
overall_task_id, description="[bold green]%s apps installed, done!" % len(apps)
)