forked from wstart/DB_BaseLine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_bascline.py
100 lines (80 loc) · 3.02 KB
/
db_bascline.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from script.mysql_baseline import *
from loghandle import *
import getopt
if __name__ == "__main__":
bannber = '''
____ ____ ____ _ _ {''' + db_baseline_basic.getVersion() + '''}
| _ \| __ )| __ ) __ _ ___ ___| (_)_ __ ___
| | | | _ \| _ \ / _` / __|/ _ \ | | '_ \ / _ \\
| |_| | |_) | |_) | (_| \__ \ __/ | | | | | __/
|____/|____/|____/ \__,_|___/\___|_|_|_| |_|\___|
(https://github.com/wstart/DB_BaseLine)
--------------------------------------------------'''
supperdb = ["mysql"]
DBnames = ",".join(supperdb)
small_helper='''
Usage: python db_baseline.py [options]
python db_baseline.py -h for more infomation
'''
helper = '''
Usage: python db_baseline.py [options]
[Options]:
-v ,--version show version
-h,--help show help
-D,--database check DataBase type,default is mysql
support Database list: ''' + DBnames + '''
-H,--host host,Default:127.0.0.1
if host is not 127.0.0.1 or localhost only check command
-P,--database-port database port,Default:Database Default port
it will set by check script
-u,--database-user database rootuser,default:root
-p,--database-password database password,default:root
'''
plog = loghandle.getLogEntity()
plog.output(bannber, "INFO", showtime=False, showlevel=False)
runconfig = {
"database": "",
"host": "",
"database_port": "",
"database_user": "",
"database_password": ""
}
try:
opts, args = getopt.getopt(sys.argv[1:], "vhD:H:P:u:p:",
["version", "help", "database=", "host=", "database-port=", "database-user=",
"database-password="])
checkscript = ""
if len(opts) == 0:
print small_helper
exit()
for o, a in opts:
if o in ("-v", "--version"):
print("DB_BASELINE : " + db_baseline_basic.getVersion())
sys.exit()
elif o in ("-h", "--help"):
print helper
sys.exit()
elif o in ("-D", "--database"):
runconfig["database"] = a
elif o in ("-H", "--host"):
runconfig["host"] = a
elif o in ("-P", "--database-port"):
runconfig["database_port"] = a
elif o in ("-U", "--database-user"):
runconfig["database_user"] = a
elif o in ("-p", "--database-password"):
runconfig["database_password"] = a
if runconfig["database"] == "mysql":
checkscript = mysql_baseline(runconfig)
if checkscript != "":
result = checkscript.runtest()
else:
plog.output("No match DataBase Type","ERROR")
print small_helper
plog.output("DBBaseline exit()")
except getopt.GetoptError:
print helper