diff options
Diffstat (limited to 'gamechest/steps_remove.py')
-rw-r--r-- | gamechest/steps_remove.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gamechest/steps_remove.py b/gamechest/steps_remove.py new file mode 100644 index 0000000..6b9144a --- /dev/null +++ b/gamechest/steps_remove.py @@ -0,0 +1,31 @@ +#!python3 + +import contextlib +import subprocess + +from stepper import Stepper + +def step_remove(queue, conf, status): + extracted_path = '/'.join(( + conf.gamedir, + strip_tar_ext(status['installed_package_name']), + )) + with contextlib.ExitStack() as stack: + proc = stack.enter_context(subprocess.Popen( + ('rm', '-rvf', '--', extracted_path), + stdout=subprocess.PIPE, + )) + selector = stack.enter_context(selectors.DefaultSelector()) + selector.register(proc.stdout, selectors.EVENT_READ) + itemscount = 0 + while True: + with contextlib.suppress(queue.Empty): + if queue.get_nowait() == Stepper.Command.STOP: + proc.terminate() + break + if ready := selector.select(0.250): + data = proc.stdout.read1() + if len(data) == 0: + break + itemscount += data.count(b'\n') + yield itemscount*100/status['installed_count'] |