Add CLI version of mysql thing

This commit is contained in:
Michael Spang 2009-11-02 20:18:55 +00:00
parent 6f4f0e6621
commit c0d9e7f3c7
4 changed files with 52 additions and 8 deletions

View File

@ -8,6 +8,7 @@ from ceo import ldapi, members, library
def start():
try:
if len(sys.argv) == 1:
print "Reading config file...",
members.configure()
library.configure()
@ -15,9 +16,11 @@ def start():
print "Connecting to LDAP..."
members.connect(AuthCallback())
if len(sys.argv) == 1:
ceo.urwid.main.start()
else:
members.configure()
library.configure()
members.connect(AuthCallback())
ceo.console.main.start()
except ldap.LOCAL_ERROR, e:
print ldapi.format_ldaperror(e)

View File

@ -5,15 +5,16 @@ from ceo.console.memberlist import MemberList
from ceo.console.updateprograms import UpdatePrograms
from ceo.console.expiredaccounts import ExpiredAccounts
from ceo.console.inactive import Inactive
from ceo.console.mysql import MySQL
commands = {
'memberlist' : MemberList(),
'updateprograms' : UpdatePrograms(),
'expiredaccounts' : ExpiredAccounts(),
'inactive': Inactive(),
'mysql': MySQL(),
}
help_opts = [ '--help', '-h' ]
def start():
args = sys.argv[1:]
if args[0] in help_opts:

38
ceo/console/mysql.py Normal file
View File

@ -0,0 +1,38 @@
from ceo import members, terms, mysql
class MySQL:
help = '''
mysql create <username>
Creates a mysql database for a user.
'''
def main(self, args):
if len(args) != 2 or args[0] != 'create':
print self.help
return
username = args[1]
problem = None
try:
password = mysql.create_mysql(username)
try:
mysql.write_mysql_info(username, password)
helpfiletext = "Settings written to ~%s/ceo-mysql-info." % username
except (KeyError, IOError, OSError), e:
helpfiletext = "An error occured writing the settings file: %s" % e
print "MySQL database created"
print ("Connection Information: \n"
"\n"
"Database: %s\n"
"Username: %s\n"
"Hostname: localhost\n"
"Password: %s\n"
"\n"
"%s\n"
% (username, username, password, helpfiletext))
except mysql.MySQLException, e:
print "Failed to create MySQL database"
print
print "We failed to create the database. The error was:\n\n%s" % e

View File

@ -29,6 +29,8 @@ def check_auth(remote_user, mysql_user, response):
if remote_user == mysql_user:
return response_message(response, 0, 'user %s creating database for self' % remote_user)
club = members.get(mysql_user)
if not club:
return response_message(response, errno.EPERM, 'user %s does not exist' % mysql_user)
if 'club' in club.get('objectClass', []):
if check_group(remote_user, mysql_user):
return response_message(response, 0, 'user %s is in club group %s' % (remote_user, mysql_user))