summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorerkin <e.altunbas@vyos.io>2021-01-31 07:26:22 +0300
committerChristian Poessinger <christian@poessinger.com>2021-01-31 10:17:32 +0100
commitb33d26ab1e5590ad8954b352ed06f9a74f492d0b (patch)
tree9dc4493e28b2fda8c4425985df967af854e57ac1 /python/vyos
parent8b66542afd8807fb75b098cdfa99ddd159ea6561 (diff)
downloadvyos-1x-b33d26ab1e5590ad8954b352ed06f9a74f492d0b.tar.gz
vyos-1x-b33d26ab1e5590ad8954b352ed06f9a74f492d0b.zip
vyos: T3274: Handle EOF in ask_yes_no()
(cherry picked from commit 55c5d662290aea9f2c3abe911bd9920f4f9d7d9a)
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/util.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 699f05892..ab5029c92 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -554,16 +554,19 @@ def ask_yes_no(question, default=False) -> bool:
from sys import stdout
default_msg = "[Y/n]" if default else "[y/N]"
while True:
- stdout.write("%s %s " % (question, default_msg))
- c = input().lower()
- if c == '':
- return default
- elif c in ("y", "ye", "yes"):
- return True
- elif c in ("n", "no"):
- return False
- else:
- stdout.write("Please respond with yes/y or no/n\n")
+ try:
+ stdout.write("%s %s " % (question, default_msg))
+ c = input().lower()
+ if c == '':
+ return default
+ elif c in ("y", "ye", "yes"):
+ return True
+ elif c in ("n", "no"):
+ return False
+ else:
+ stdout.write("Please respond with yes/y or no/n\n")
+ except EOFError:
+ stdout.write("\nPlease respond with yes/y or no/n\n")
def is_admin() -> bool: