-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
249 lines (218 loc) · 6.94 KB
/
config.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
from configparser import *
import os
# 读取ini文件
def read_cf():
if os.path.isfile("config.ini") is False:
print("\n配置文件config.ini不存在,请根据config.ini.example创建!")
input("回车以退出")
exit(1)
cf = RawConfigParser()
cf.read("config.ini", encoding="utf8")
return cf
# 获取数据库配置
def get_mysql_host():
cf = read_cf()
try:
mysql_host = cf.get("mysql", "host").strip('"')
except NoSectionError:
print("\n[mysql]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nhost不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return mysql_host
def get_mysql_port():
cf = read_cf()
try:
mysql_port = cf.get("mysql", "port").strip('"')
mysql_port = int(mysql_port)
except NoSectionError:
print("\n[mysql]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nport不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return mysql_port
def get_mysql_user():
cf = read_cf()
try:
mysql_user = cf.get("mysql", "user").strip('"')
except NoSectionError:
print("\n[mysql]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nuser不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return mysql_user
def get_mysql_password():
cf = read_cf()
try:
mysql_password = cf.get("mysql", "password").strip('"')
except NoSectionError:
print("\n[mysql]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nexam_month不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return mysql_password
def get_mysql_database():
cf = read_cf()
try:
mysql_database = cf.get("mysql", "database").strip('"')
except NoSectionError:
print("\n[mysql]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\ndatabase不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return mysql_database
def get_mysql_charset():
cf = read_cf()
try:
mysql_charset = cf.get("mysql", "charset").strip('"')
except NoSectionError:
print("\n[mysql]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\ncharset不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return mysql_charset
# 获取邮件系统设置
def get_email_host():
cf = read_cf()
try:
email_host = cf.get("email", "host").strip('"')
except NoSectionError:
print("\n[email]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nhost不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return email_host
def get_email_passwd():
cf = read_cf()
try:
email_passwd = cf.get("email", "passwd").strip('"')
except NoSectionError:
print("\n[email]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\npasswd不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return email_passwd
def get_email_from_addr():
cf = read_cf()
try:
email_from_addr = cf.get("email", "from_addr").strip('"')
except NoSectionError:
print("\n[email]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nfrom_addr不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return email_from_addr
def get_email_from_addr_name():
cf = read_cf()
try:
email_from_addr_name = cf.get("email", "from_addr_name").strip('"')
except NoSectionError:
print("\n[email]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nfrom_addr_name不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return email_from_addr_name
def get_email_admin_addr():
cf = read_cf()
try:
email_admin_addr = cf.get("email", "admin_addr").strip('"')
except NoSectionError:
print("\n[email]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nadmin_addr不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return email_admin_addr
# 获取管理员设置
def get_admin_zkzh():
cf = read_cf()
try:
admin_zkzh = cf.get("admin", "zkzh").strip('"')
except NoSectionError:
print("\n[admin]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nzkzh不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return admin_zkzh
def get_admin_name():
cf = read_cf()
try:
admin_name = cf.get("admin", "name").strip('"')
except NoSectionError:
print("\n[admin]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nname不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return admin_name
def get_admin_exam_month():
cf = read_cf()
try:
admin_exam_month = cf.get("admin", "exam_month").strip('"')
admin_exam_month = int(admin_exam_month)
if admin_exam_month not in [1,4,7,10]:
print("\nexam_month的值不正确,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoSectionError:
print("\n[admin]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nexam_month不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
return admin_exam_month
# 设置要检查新成绩的考期
def set_admin_exam_month(mon):
mon = "\"" + str(mon) + "\""
cf = read_cf()
try:
cf.set("admin", "exam_month", mon)
cf.write(open("config.ini", "w", encoding="utf8"))
return True
except NoSectionError:
print("\n[admin]不存在,请检查config.ini文件")
input("回车以退出")
exit(1)
except NoOptionError:
print("\nexam_month不存在,请检查config.ini文件")
input("回车以退出")
exit(1)