forked from doveccl/DOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setConf.py
46 lines (37 loc) · 976 Bytes
/
setConf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
#coding: utf-8
import pymysql, os
db_user = ''
db_pwd = ''
def tryConn():
global db_user, db_pwd
try:
conn = pymysql.connect(host='localhost', user=db_user, passwd=db_pwd)
conn.close()
return True
except pymysql.Error, e:
print 'Mysql Error %d: %s' % (e.args[0], e.args[1])
return False
def getConf():
global db_user, db_pwd
db_user = raw_input('Enter MySQL Username:')
db_pwd = raw_input('Enter MySQL Password:')
if db_user == '':
db_user = 'root'
if db_pwd == '':
db_pwd = 'root'
return tryConn()
if __name__ == '__main__':
while not getConf():
print 'Unable to connect to MySQL'
print 'Please check your input and enter again'
print 'You have entered %s %s' % (db_user, db_pwd)
conf = file('/home/doj/db.conf', 'w')
conf.write('''{
"db_host": "localhost",
"db_user": "%s",
"db_pwd": "%s",
"db_name": "doj"
}''' % (db_user, db_pwd))
conf.close()
os.system("mysql -u%s -p%s < doj.sql" % (db_user, db_pwd))