diff options
author | V3n3RiX <venerix@koprulu.sector> | 2024-02-25 19:22:11 +0000 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2024-02-25 19:22:11 +0000 |
commit | 17b776830e4468080c1b0f09685b4aa4f7b9eaf3 (patch) | |
tree | 740ba94196aeb4ed8e1eead48b620b96d384d825 /src/backend/upgrade.py | |
parent | e3fa4634750ccceb23998fadefc249b35f86ca5b (diff) |
bugfix : https://bugs.redcorelinux.org/show_bug.cgi?id=143
Diffstat (limited to 'src/backend/upgrade.py')
-rw-r--r-- | src/backend/upgrade.py | 94 |
1 files changed, 90 insertions, 4 deletions
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']: |