Check file type being uploaded. (#2756)
[ExpressLRS.git] / src / python / query_yes_no.py
blob308a3c23524341b5e18f5d95d8c6ef63e4c4ffac
1 import sys
2 from external.inputimeout import inputimeout, TimeoutOccurred
5 def query_yes_no(question='') -> bool: #https://code.activestate.com/recipes/577058/
6 """Ask a yes/no question via raw_input() and return their answer.
7 "question" is a string that is presented to the user.
8 The "answer" return value is True for "yes" or False for "no".
9 """
10 # Always return false if not in an interactive shell
11 if not sys.stdin.isatty():
12 return False
14 valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
16 while True:
17 choice = ''
18 try:
19 choice = inputimeout(prompt=question, timeout=5)
20 except TimeoutOccurred:
21 sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n')")
22 sys.stdout.flush()
24 if choice in valid:
25 return valid[choice]