From 35d19fd293a758c0696410a490daa349bfcc9e21 Mon Sep 17 00:00:00 2001
From: Tomas Jelinek <tojeline@redhat.com>
Date: Mon, 8 Aug 2016 15:05:51 +0200
Subject: [PATCH] handle exceptions when waiting for response from user
---
pcs/utils.py | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/pcs/utils.py b/pcs/utils.py
index 8b2cf7c..53cc0b0 100644
--- a/pcs/utils.py
+++ b/pcs/utils.py
@@ -1801,14 +1801,24 @@ def get_terminal_input(message=None):
if message:
sys.stdout.write(message)
sys.stdout.flush()
- if PYTHON2:
- return raw_input("")
- else:
- return input("")
+ try:
+ if PYTHON2:
+ return raw_input("")
+ else:
+ return input("")
+ except EOFError:
+ return ""
+ except KeyboardInterrupt:
+ print("Interrupted")
+ sys.exit(1)
def get_terminal_password(message="Password: "):
- if sys.stdout.isatty():
- return getpass.getpass(message)
+ if sys.stdin.isatty():
+ try:
+ return getpass.getpass(message)
+ except KeyboardInterrupt:
+ print("Interrupted")
+ sys.exit(1)
else:
return get_terminal_input(message)
--
1.8.3.1