From 2df4347b44ff6e45ed6b4a66332efae51056c2ef Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 18 Oct 2020 20:49:44 +0200 Subject: Added a slightly convoluted but non-intrusive 'are you sure?' on Ctrl+C/any input. --- examples/guided.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/guided.py b/examples/guided.py index 12d34194..067d591f 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -1,5 +1,20 @@ import archinstall -import getpass, time, json, sys +import getpass, time, json, sys, signal +from select import epoll, EPOLLIN + +""" +This signal-handler chain (and global variable) +is used to trigger the "Are you sure you want to abort?" question. +""" +SIG_TRIGGER = False +def kill_handler(sig, frame): + print() + exit(0) +def sig_handler(sig, frame): + global SIG_TRIGGER + SIG_TRIGGER = True + signal.signal(signal.SIGINT, kill_handler) +signal.signal(signal.SIGINT, sig_handler) def perform_installation(device, boot_partition, language, mirrors): """ @@ -148,7 +163,11 @@ print() Issue a final warning before we continue with something un-revertable. We mention the drive one last time, and count from 5 to 0. """ + print(f' ! Formatting {harddrive} in ', end='') + +poller = epoll() +poller.register(sys.stdin.fileno(), EPOLLIN) for i in range(5, 0, -1): print(f"{i}", end='') @@ -156,6 +175,16 @@ for i in range(5, 0, -1): sys.stdout.flush() time.sleep(0.25) print(".", end='') + + if list(poller.poll(0.25)) or SIG_TRIGGER: + abort = input('\nDo you really want to abort (y/n)? ') + if abort.strip() != 'n': + exit(0) + + if SIG_TRIGGER is False: + sys.stdin.read() + SIG_TRIGGER = False + signal.signal(signal.SIGINT, sig_handler) print() """ Setup the blockdevice, filesystem (and optionally encryption). -- cgit v1.2.3-54-g00ecf