From b359e187fc12c76c3d941b0f1f4b7a48e538cccd Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sat, 8 Apr 2023 22:04:51 +0100 Subject: setprofile : make sure it stops with keyboard interrupt --- src/backend/setprofile.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/backend') diff --git a/src/backend/setprofile.py b/src/backend/setprofile.py index 6219428..5d2f42d 100644 --- a/src/backend/setprofile.py +++ b/src/backend/setprofile.py @@ -2,20 +2,52 @@ import animation import platform +import signal import subprocess +def sigint_handler(signal, frame): + sys.exit(0) + + +signal.signal(signal.SIGINT, sigint_handler) + + @animation.wait('setting up profile') def start(): if platform.uname()[4] == 'x86_64': e_exe = subprocess.Popen( ['eselect', 'profile', 'set', 'default/linux/amd64/17.1/hardened']) - e_exe.wait() + try: + e_exe.wait() + except KeyboardInterrupt: + e_exe.terminate() + try: + e_exe.wait(1) + except subprocess.TimeoutExpired: + e_exe.kill() + sys.exit() if platform.uname()[4] == 'aarch64': e_exe = subprocess.Popen( ['eselect', 'profile', 'set', 'default/linux/arm64/17.0']) - e_exe.wait() + try: + e_exe.wait() + except KeyboardInterrupt: + e_exe.terminate() + try: + e_exe.wait(1) + except subprocess.TimeoutExpired: + e_exe.kill() + sys.exit() env_exe = subprocess.Popen(['env-update'], stdout=subprocess.DEVNULL) - env_exe.wait() + try: + env_exe.wait() + except KeyboardInterrupt: + env_exe.terminate() + try: + env_exe.wait(1) + except subprocess.TimeoutExpired: + env_exe.kill() + sys.exit() -- cgit v1.2.3