summaryrefslogtreecommitdiffstats
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
parent08c0dacd3186052739cb7fa2f735a2b77d8c4365 (diff)
downloadpykolab-d7042619ed10491e79282a6bad38327891bd2081.tar.gz
Provide a mechanism to select a process in which an existing MySQL server is used (#1177)
-rw-r--r--pykolab/setup/setup_mysql.py75
-rw-r--r--pykolab/utils.py26
2 files changed, 74 insertions, 27 deletions
diff --git a/pykolab/setup/setup_mysql.py b/pykolab/setup/setup_mysql.py
index 0536304..8d419ad 100644
--- a/pykolab/setup/setup_mysql.py
+++ b/pykolab/setup/setup_mysql.py
@@ -58,33 +58,54 @@ def execute(*args, **kw):
log.error(_("Could not configure to start on boot, the " + \
"MySQL database service."))
- print >> sys.stderr, utils.multiline_message(
- _("""
- Please supply a root password for MySQL. This password will
- be the administrative user for this MySQL server, and it
- should be kept a secret. After this setup process has
- completed, Kolab is going to discard and forget about this
- password, but you will need it for administrative tasks in
- MySQL.
- """)
- )
-
- mysql_root_password = utils.ask_question(
- _("MySQL root password"),
- default=utils.generate_password(),
- password=True,
- confirm=True
- )
-
- p1 = subprocess.Popen(['echo', 'UPDATE mysql.user SET Password=PASSWORD(\'%s\') WHERE User=\'root\';' % (mysql_root_password)], stdout=subprocess.PIPE)
- p2 = subprocess.Popen(['mysql'], stdin=p1.stdout)
- p1.stdout.close()
- p2.communicate()
-
- p1 = subprocess.Popen(['echo', 'FLUSH PRIVILEGES;'], stdout=subprocess.PIPE)
- p2 = subprocess.Popen(['mysql'], stdin=p1.stdout)
- p1.stdout.close()
- p2.communicate()
+ options = {
+ 1: "Existing MySQL server (with root password already set).",
+ 2: "New MySQL server (needs to be initialized)."
+ }
+
+ answer = utils.ask_menu(_("What MySQL server are we setting up?"), options)
+
+ if answer == "1" or answer == 1:
+ print >> sys.stderr, utils.multiline_message(
+ _("""
+ Please supply the root password for MySQL, so we can set
+ up user accounts for other components that use MySQL.
+ """)
+ )
+
+ mysql_root_password = utils.ask_question(
+ _("MySQL root password"),
+ password=True
+ )
+
+ else:
+ print >> sys.stderr, utils.multiline_message(
+ _("""
+ Please supply a root password for MySQL. This password
+ will be the administrative user for this MySQL server,
+ and it should be kept a secret. After this setup process
+ has completed, Kolab is going to discard and forget
+ about this password, but you will need it for
+ administrative tasks in MySQL.
+ """)
+ )
+
+ mysql_root_password = utils.ask_question(
+ _("MySQL root password"),
+ default=utils.generate_password(),
+ password=True,
+ confirm=True
+ )
+
+ p1 = subprocess.Popen(['echo', 'UPDATE mysql.user SET Password=PASSWORD(\'%s\') WHERE User=\'root\';' % (mysql_root_password)], stdout=subprocess.PIPE)
+ p2 = subprocess.Popen(['mysql'], stdin=p1.stdout)
+ p1.stdout.close()
+ p2.communicate()
+
+ p1 = subprocess.Popen(['echo', 'FLUSH PRIVILEGES;'], stdout=subprocess.PIPE)
+ p2 = subprocess.Popen(['mysql'], stdin=p1.stdout)
+ p1.stdout.close()
+ p2.communicate()
data = """
[mysql]
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)