-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.py
32 lines (30 loc) · 974 Bytes
/
common.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/7/16 14:50
# @Author : Shijun Gong
# @Version : 0.1.0
# @File : common.py
# @Software: PyCharm
def read_conf():
un = ''
pw = ''
ip = ''
try:
with open('user.conf', 'r') as file:
for line in file.readlines():
line = line.strip()
if line == '':
continue
if line[0] == '#':
continue
if line.split('=')[0].strip() == 'username':
un = line.split('=')[1].strip()
elif line.split('=')[0].strip() == 'password':
pw = line.split('=')[1].strip()
else:
print('user.conf is a error format. \n')
except IOError as e:
print('cannot read user.conf file--' + str(e) + ', please create user.conf file. \n')
return un, pw
if __name__ == '__main__':
print(read_conf())