-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigparser.py
49 lines (42 loc) · 1.46 KB
/
Configparser.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
import configparser
import os
import sys
from functools import lru_cache
class Configparser(object):
# PRIVATE METHODS...
@lru_cache(maxsize=2048)
def __init__(self,fileName):
self._CONFIG_PATH = 'config/'
self._cfgparser = configparser.SafeConfigParser()
self._cfgparser.optionxform = str
self.loadConfig(fileName)
@lru_cache(maxsize=2048)
def loadConfig(self,fileName):
self._cfgparser.readfp(open(self.getAbsPath(self._CONFIG_PATH + fileName)))
@lru_cache(maxsize=2048)
def getDirName(self):
try:
dirname = os.path.dirname(os.path.abspath(__file__))
except NameError:
dirname = os.path.dirname(os.path.abspath(sys.argv[0]))
return dirname
@lru_cache(maxsize=2048)
def getAbsPath(self,fileName):
return os.path.join(self.getDirName(),fileName)
@lru_cache(maxsize=2048)
def getConfig(self):
return self._cfgparser
# PUBLIC METHODS FOLLOW...
@lru_cache(maxsize=2048)
def getConfigElement(self,section,key):
return self.getConfig().get(section,key)
@lru_cache(maxsize=2048)
def getConfigSection(self,section):
return self.getConfig().items(section)
#def main():
#c = Configparser('models.conf')
#print(c.getConfigElement('model','keys'))
#print(c.getConfigSection('model_input'))
#print(c.getConfigSection.cache_info())
#print(c.getConfigSection('model_input'))
#print(c.getConfigSection.cache_info())