From c51107ae2b529f7f0375a817852eae78236899b4 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Thu, 10 Sep 2009 15:37:41 -0400 Subject: [PATCH] Write mysql file to ~club --- ceo/mysql.py | 28 +++++++++++++++++++++++++++- ceo/urwid/databases.py | 10 ++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ceo/mysql.py b/ceo/mysql.py index f6b3e695b..02461bc8d 100644 --- a/ceo/mysql.py +++ b/ceo/mysql.py @@ -1,10 +1,36 @@ -import os, re, subprocess, ldap, socket +import os, re, subprocess, ldap, socket, pwd from ceo import conf, ldapi, terms, remote, ceo_pb2 from ceo.excep import InvalidArgument class MySQLException(Exception): pass +def write_mysql_info(username, password): + homedir = pwd.getpwnam(username).pw_dir + password_file = '%s/ceo-mysql-info' % homedir + if os.path.exists(password_file): + os.rename(password_file, password_file + '.old') + fd = os.open(password_file, os.O_CREAT|os.O_EXCL|os.O_WRONLY, 0660) + fh = os.fdopen(fd, 'w') + fh.write("""MySQL Database Information for %(username)s + +Your new MySQL database was created. To connect, use +the following options: + +Database: %(username)s +Username: %(username)s +Password: %(password)s +Hostname: localhost + +The command to connect using the MySQL command-line client is + + mysql %(username)s -u %(username)s -p + +This database is only accessible from caffeine. +""" % { 'username': username, 'password': password }) + + fh.close() + def create_mysql(username): try: request = ceo_pb2.AddMySQLUser() diff --git a/ceo/urwid/databases.py b/ceo/urwid/databases.py index a61120dc6..3825a96f6 100644 --- a/ceo/urwid/databases.py +++ b/ceo/urwid/databases.py @@ -60,6 +60,12 @@ class EndPage(WizardPanel): problem = None try: password = mysql.create_mysql(self.state['userid']) + + try: + mysql.write_mysql_info(self.state['userid'], password) + helpfiletext = "Settings written to ~%s/ceo-mysql-info." % self.state['userid'] + except (KeyError, IOError, OSError), e: + helpfiletext = "An error occured writing the settings file: %s" % e self.headtext.set_text("MySQL database created") self.midtext.set_text("Connection Information: \n" "\n" @@ -68,8 +74,8 @@ class EndPage(WizardPanel): "Hostname: localhost\n" "Password: %s\n" "\n" - "Note: Databases are only accessible from caffeine\n" - % (self.state['userid'], self.state['userid'], password)) + "%s\n" + % (self.state['userid'], self.state['userid'], password, helpfiletext)) except mysql.MySQLException, e: self.headtext.set_text("Failed to create MySQL database") self.midtext.set_text("We failed to create the database. The error was:\n\n%s" % e)