-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProperties.py
32 lines (28 loc) · 1.05 KB
/
Properties.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
class Properties(object):
def __init__(self, file_name):
self.fileName = file_name
self.properties = {}
def __getDict(self, str_name, dict_name, value):
if str_name.find('.') > 0:
k = str_name.split('.')[0]
dict_name.setdefault(k, {})
return self.__getDict(str_name[len(k) + 1:], dict_name[k], value)
else:
dict_name[str_name] = value
return
def get_properties(self):
try:
pro_file = open(self.fileName, 'r')
for line in pro_file.readlines():
line = line.strip().replace('\n', '')
if line.find("#") != -1:
line = line[0:line.find('#')]
if line.find('=') > 0:
strs = line.split('=')
strs[1] = line[len(strs[0]) + 1:]
self.__getDict(strs[0].strip(), self.properties, strs[1].strip())
except Exception as e:
raise e
else:
pro_file.close()
return self.properties