diff options
Diffstat (limited to 'gamechestcli/gamechest/processor.py')
-rw-r--r-- | gamechestcli/gamechest/processor.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/gamechestcli/gamechest/processor.py b/gamechestcli/gamechest/processor.py new file mode 100644 index 0000000..794deb8 --- /dev/null +++ b/gamechestcli/gamechest/processor.py @@ -0,0 +1,41 @@ +import contextlib +import selectors + +from rich.progress import Progress as RichProgress +from rich import print + + +def process_task(title, task): + with contextlib.ExitStack() as stack: + runner = stack.enter_context(task()) + selector = stack.enter_context(selectors.DefaultSelector()) + selector.register(runner.get_read_fd(), selectors.EVENT_READ) + rich_progress = stack.enter_context(RichProgress()) + known_total = 100 + global_id = rich_progress.add_task(title, total=known_total) + last_step = None + while (rc := runner.poll()) is None: + if selector.select(): + progress = runner.progress_read() + #rich_progress.console.log(progress) + known_total = progress.steps_count*100 + rich_progress.update(global_id, + completed=progress.step*100+progress.percent, + total=known_total) + if last_step != progress.step: + if last_step is not None: + rich_progress.update(step_id, completed=100) + else: + rich_progress.console.print('Total steps:', + progress.steps_count) + last_step = progress.step + step_id = rich_progress.add_task( + f'Step {progress.step}', total=100) + rich_progress.update(step_id, completed=progress.percent) + rich_progress.update(step_id, completed=100) + rich_progress.update(global_id, completed=known_total) + #rich_progress.console.print('installation ended with code:', rc) + if rc != 0: + # success, update db to say installed + status_db.set_installed(game_info) + print('ended with code:', rc) |