summaryrefslogtreecommitdiff
path: root/linaropy/rninput.py
diff options
context:
space:
mode:
Diffstat (limited to 'linaropy/rninput.py')
-rw-r--r--linaropy/rninput.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/linaropy/rninput.py b/linaropy/rninput.py
index 86d3d90..d440a5b 100644
--- a/linaropy/rninput.py
+++ b/linaropy/rninput.py
@@ -6,30 +6,35 @@ import os.path
# @accept - The list of valid responses.
# @retry - Whether to retry on a malformed input.
# Returns 'y' or 'no'
+
+
def yninput(message, default="n", accept=['yes', 'y', 'no', 'n'], retry=True):
# TODO: Test this
if default.lower() not in accept:
- raise TypeError('Default as %s is not in list of accepted responses.' % default)
+ raise TypeError(
+ 'Default as %s is not in list of accepted responses.' % default)
- default_msg=" [y/N]: "
+ default_msg = " [y/N]: "
if default.lower() == "y" or default.lower() == "yes":
- default_msg=" [Y/n]: "
+ default_msg = " [Y/n]: "
while(1):
- answer=raw_input(message + default_msg) or default.lower()
- if answer.lower() not in accept and retry:
- print "'%s' is an invalid response. Please try again." % answer.lower()
- continue
+ answer = raw_input(message + default_msg) or default.lower()
+ if answer.lower() not in accept and retry:
+ print "'%s' is an invalid response. Please try again." % answer.lower()
+ continue
else:
if answer.lower() == "yes" or answer.lower() == "y":
- return "y"
+ return "y"
return "n"
# TODO: Test with a directory returned as the answer.
-def finput(message,orval):
+
+
+def finput(message, orval):
while(1):
- answer=raw_input(message) or orval
- if os.path.exists(answer) and os.path.isfile(answer):
- return answer
+ answer = raw_input(message) or orval
+ if os.path.exists(answer) and os.path.isfile(answer):
+ return answer
- print "%s doesn't exist or isn't a regular file. Try again." % answer
+ print "%s doesn't exist or isn't a regular file. Try again." % answer