diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2010-10-08 13:26:39 +0200 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2010-10-08 13:26:39 +0200 |
commit | 11c2e732e4ae8dd1e8b5eee6e7de8d34f63568a1 (patch) | |
tree | 1292a13b7d97a4ce7a0f2f487d9387f0289d56ee /pykolab/utils.py | |
parent | 05e06399f287e7bf6387b3fd8eb7100df607bda4 (diff) | |
download | pykolab-11c2e732e4ae8dd1e8b5eee6e7de8d34f63568a1.tar.gz |
A simple dialog asking for confirmation
Diffstat (limited to 'pykolab/utils.py')
-rw-r--r-- | pykolab/utils.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py index a5c0f1f..4540fcd 100644 --- a/pykolab/utils.py +++ b/pykolab/utils.py @@ -20,6 +20,40 @@ def ask_question(question, default="", password=False): else: return answer +def ask_confirmation(question, default="y", all_inclusive_no=True): + if default in [ "y", "Y" ]: + default_answer = True + default_no = "n" + default_yes = "Y" + elif default in [ "n", "N" ]: + default_answer = True + default_no = "N" + default_yes = "y" + else: + # This is a 'yes' or 'no' question the user + # needs to provide the full yes or no for. + default_no = "'no'" + default_yes = "Please type 'yes'" + answer = False + while answer == False: + answer = raw_input("%s [%s/%s]: " %(question,default_yes,default_no)) + # Parse answer and set back to False if not appropriate + if all_inclusive_no: + if not answer in [ "y", "Y", "yes" ]: + return False + else: + return True + else: + if answer in [ "y", "Y", "yes" ]: + return True + elif answer in [ "n", "N", "no" ]: + return False + elif answer == "" and not default_answer == None: + return default_answer + else: + answer = False + print >> sys.stderr, _("Please answer 'yes' or 'no'.") + def parse_input(_input, splitchars= [ ' ' ]): """ Split the input string using the split characters defined |