From 17b776830e4468080c1b0f09685b4aa4f7b9eaf3 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sun, 25 Feb 2024 19:22:11 +0000 Subject: bugfix : https://bugs.redcorelinux.org/show_bug.cgi?id=143 --- src/backend/upgrade.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 4 deletions(-) (limited to 'src/backend/upgrade.py') diff --git a/src/backend/upgrade.py b/src/backend/upgrade.py index 61e40ed..31e3463 100644 --- a/src/backend/upgrade.py +++ b/src/backend/upgrade.py @@ -1,9 +1,11 @@ #!/usr/bin/python3 import atexit +import fcntl import io import os import pickle +import selectors import signal import subprocess import sys @@ -18,6 +20,26 @@ import sisyphus.syncdb import sisyphus.update +def set_nonblocking(fd): + flags = fcntl.fcntl(fd, fcntl.F_GETFL) + fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) + + +def spinner_animation(): + spinner = ['-', '\\', '|', '/'] + sel = selectors.DefaultSelector() + sel.register(sys.stdin, selectors.EVENT_READ) + + for _ in range(10): + for char in spinner: + sys.stdout.write('\b' + char) + sys.stdout.flush() + events = sel.select(timeout=0.1) + if events: + return + sys.stdout.write('\b') + + def sigint_handler(signal, frame): sys.exit(0) @@ -92,7 +114,21 @@ def start(ebuild=False, gfx_ui=False): p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--update', '--deep', '--newuse', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world']) try: - p_exe.wait() + set_nonblocking(sys.stdout.fileno()) + spinner_animation() + + sel = selectors.DefaultSelector() + sel.register(sys.stdin, selectors.EVENT_READ) + + while True: + events = sel.select(timeout=0.1) + for key, mask in events: + if key.fileobj == sys.stdin: + line = sys.stdin.readline().strip() + if line.lower() == 'q': + sys.exit() + if p_exe.poll() is not None: + break except KeyboardInterrupt: p_exe.terminate() try: @@ -100,6 +136,8 @@ def start(ebuild=False, gfx_ui=False): except subprocess.TimeoutExpired: p_exe.kill() sys.exit() + finally: + p_exe.wait() sisyphus.syncdb.lcl_tbl() break elif user_input.lower() in ['no', 'n']: @@ -131,7 +169,21 @@ def start(ebuild=False, gfx_ui=False): p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--update', '--deep', '--newuse', '--usepkg', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world']) try: - p_exe.wait() + set_nonblocking(sys.stdout.fileno()) + spinner_animation() + + sel = selectors.DefaultSelector() + sel.register(sys.stdin, selectors.EVENT_READ) + + while True: + events = sel.select(timeout=0.1) + for key, mask in events: + if key.fileobj == sys.stdin: + line = sys.stdin.readline().strip() + if line.lower() == 'q': + sys.exit() + if p_exe.poll() is not None: + break except KeyboardInterrupt: p_exe.terminate() try: @@ -139,6 +191,8 @@ def start(ebuild=False, gfx_ui=False): except subprocess.TimeoutExpired: p_exe.kill() sys.exit() + finally: + p_exe.wait() sisyphus.syncdb.lcl_tbl() break elif user_input.lower() in ['no', 'n']: @@ -163,7 +217,21 @@ def start(ebuild=False, gfx_ui=False): p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world']) try: - p_exe.wait() + set_nonblocking(sys.stdout.fileno()) + spinner_animation() + + sel = selectors.DefaultSelector() + sel.register(sys.stdin, selectors.EVENT_READ) + + while True: + events = sel.select(timeout=0.1) + for key, mask in events: + if key.fileobj == sys.stdin: + line = sys.stdin.readline().strip() + if line.lower() == 'q': + sys.exit() + if p_exe.poll() is not None: + break except KeyboardInterrupt: p_exe.terminate() try: @@ -171,6 +239,8 @@ def start(ebuild=False, gfx_ui=False): except subprocess.TimeoutExpired: p_exe.kill() sys.exit() + finally: + p_exe.wait() sisyphus.syncdb.lcl_tbl() break elif user_input.lower() in ['no', 'n']: @@ -249,7 +319,21 @@ def start(ebuild=False, gfx_ui=False): p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world']) try: - p_exe.wait() + set_nonblocking(sys.stdout.fileno()) + spinner_animation() + + sel = selectors.DefaultSelector() + sel.register(sys.stdin, selectors.EVENT_READ) + + while True: + events = sel.select(timeout=0.1) + for key, mask in events: + if key.fileobj == sys.stdin: + line = sys.stdin.readline().strip() + if line.lower() == 'q': + sys.exit() + if p_exe.poll() is not None: + break except KeyboardInterrupt: p_exe.terminate() try: @@ -257,6 +341,8 @@ def start(ebuild=False, gfx_ui=False): except subprocess.TimeoutExpired: p_exe.kill() sys.exit() + finally: + p_exe.wait() sisyphus.syncdb.lcl_tbl() break elif user_input.lower() in ['no', 'n']: -- cgit v1.2.3