summaryrefslogtreecommitdiffstats
path: root/pykolab/utils.py
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-11-22 09:29:54 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-11-22 09:29:54 +0000
commitd7042619ed10491e79282a6bad38327891bd2081 (patch)
tree36d57e7740ca83da772aadf34646972f63977731 /pykolab/utils.py
parent08c0dacd3186052739cb7fa2f735a2b77d8c4365 (diff)
downloadpykolab-d7042619ed10491e79282a6bad38327891bd2081.tar.gz
Provide a mechanism to select a process in which an existing MySQL server is used (#1177)
Diffstat (limited to 'pykolab/utils.py')
-rw-r--r--pykolab/utils.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index a4d8455..4516297 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -123,6 +123,32 @@ def ask_confirmation(question, default="y", all_inclusive_no=True):
else:
return True
+def ask_menu(question, options={}):
+ print question
+ answer_correct = False
+ max_key_length = 0
+
+ keys = options.keys()
+ keys.sort()
+
+ while not answer_correct:
+ for key in keys:
+ key_length = len("%s" % key)
+ if key_length > max_key_length:
+ max_key_length = key_length
+
+ str_format = "%%%ds" % max_key_length
+
+ for key in keys:
+ print " - " + eval("str_format % key") + ": " + options[key]
+
+ answer = raw_input(_("Choice") + ": ")
+
+ if answer in [str(x) for x in options.keys()]:
+ answer_correct = True
+
+ return answer
+
def ensure_directory(_dir, _user='root', _group='root'):
if not os.path.isdir(_dir):
os.makedirs(_dir)