summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotheus Pokorra <tp@tbits.net>2015-04-13 09:11:34 (GMT)
committerTimotheus Pokorra <tp@tbits.net>2015-04-13 09:15:28 (GMT)
commit331cb5edc84e784b164f7e7fb67a835c606c13fa (patch)
tree303db50ee42c18d4d16914ec976319122cdb3dee
parent2cca820836c530518474b45d27441b4b4be9d923 (diff)
downloadpykolab-331cb5edc84e784b164f7e7fb67a835c606c13fa.tar.gz
implementing --default, --yes and --quiet parameters for setup-kolab (#2598)
-rw-r--r--pykolab/conf/__init__.py6
-rw-r--r--pykolab/utils.py23
2 files changed, 29 insertions, 0 deletions
diff --git a/pykolab/conf/__init__.py b/pykolab/conf/__init__.py
index e05f140..faf87d9 100644
--- a/pykolab/conf/__init__.py
+++ b/pykolab/conf/__init__.py
@@ -278,6 +278,12 @@ class Conf(object):
help = _("Set the debugging " + \
"verbosity. Maximum is 9, tracing " + \
"protocols like LDAP, SQL and IMAP."))
+
+ runtime_group.add_option( "-e", "--default",
+ dest = "answer_default",
+ action = "store_true",
+ default = False,
+ help = _("Use the default answer to all questions."))
runtime_group.add_option( "-l",
dest = "loglevel",
diff --git a/pykolab/utils.py b/pykolab/utils.py
index a9537dd..6838589 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -30,6 +30,7 @@ from pykolab import constants
from pykolab.translate import _
log = pykolab.getLogger('pykolab.utils')
+conf = pykolab.getConf()
def ask_question(question, default="", password=False, confirm=False):
"""
@@ -42,6 +43,12 @@ def ask_question(question, default="", password=False, confirm=False):
Usage: pykolab.utils.ask_question("What is the server?", default="localhost")
"""
+
+ if not default == "" and not default == None and conf.cli_keywords.answer_default:
+ if not conf.cli_keywords.quiet:
+ print ("%s [%s]: " % (question, default))
+ return default
+
if password:
if default == "" or default == None:
answer = getpass.getpass("%s: " % (question))
@@ -108,6 +115,14 @@ def ask_confirmation(question, default="y", all_inclusive_no=True):
default_no = "'no'"
default_yes = "Please type 'yes'"
+ if conf.cli_keywords.answer_yes or (conf.cli_keywords.answer_default and default_answer is not None):
+ if not conf.cli_keywords.quiet:
+ print ("%s [%s/%s]: " % (question,default_yes,default_no))
+ if conf.cli_keywords.answer_yes:
+ return True
+ if conf.cli_keywords.answer_default:
+ return default_answer
+
answer = False
while answer == False:
answer = raw_input("%s [%s/%s]: " % (question,default_yes,default_no))
@@ -129,6 +144,11 @@ def ask_confirmation(question, default="y", all_inclusive_no=True):
return True
def ask_menu(question, options={}, default=''):
+ if not default == '' and conf.cli_keywords.answer_default:
+ if not conf.cli_keywords.quiet:
+ print question + " [" + default + "]:"
+ return default
+
if not default == '':
print question + " [" + default + "]:"
else:
@@ -280,6 +300,9 @@ def generate_password():
return output
def multiline_message(message):
+ if conf.cli_keywords.quiet:
+ return ""
+
column_width = 80
# First, replace all occurences of "\n"