summaryrefslogtreecommitdiff
path: root/pykolab/utils.py
diff options
context:
space:
mode:
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: