summaryrefslogtreecommitdiff
path: root/pykolab/utils.py
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-10 13:41:16 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-10 13:41:16 (GMT)
commit167d20723f7033014de09049266c42f1c2bd465a (patch)
tree6255f543fae8db5106bb038286d3d74b57114586 /pykolab/utils.py
parentc06a170dc7a8c0f91b58d4a9a5b2fc5900438b55 (diff)
downloadpykolab-167d20723f7033014de09049266c42f1c2bd465a.tar.gz
Allow utils.ask_question() to request confirmation of the input
Diffstat (limited to 'pykolab/utils.py')
-rw-r--r--pykolab/utils.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 0ba203a..5e32880 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -24,7 +24,7 @@ import sys
from pykolab import constants
from pykolab.translate import _
-def ask_question(question, default="", password=False):
+def ask_question(question, default="", password=False, confirm=False):
"""
Ask a question on stderr.
@@ -46,6 +46,26 @@ def ask_question(question, default="", password=False):
else:
answer = raw_input("%s [%s]: " % (question, default))
+ if not answer == "" and not default == "":
+ if confirm:
+ answer_confirm = None
+ answer_confirmed = False
+ while not answer_confirmed:
+ if default == "":
+ answer_confirm = raw_input("Confirm %s: " % (question))
+ else:
+ answer_confirm = raw_input("Confirm %s [%s]: " % (question, default))
+
+ if not answer_confirm == answer:
+ print >> sys.stderr, _("Incorrect confirmation. " + \
+ "Please try again.")
+ if default == "":
+ answer = raw_input("%s: " % (question))
+ else:
+ answer = raw_input("%s [%s]: " % (question, default))
+ else:
+ answer_confirmed = True
+
if answer == "":
return default
else: