Write mysql file to ~club

This commit is contained in:
Michael Spang 2009-09-10 15:37:41 -04:00
parent c7bd720124
commit c51107ae2b
2 changed files with 35 additions and 3 deletions

View File

@ -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()

View File

@ -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)