-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelConfig.py
68 lines (59 loc) · 2.19 KB
/
ModelConfig.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
import Configparser
import copy
from functools import lru_cache
@lru_cache(maxsize=2048)
class ModelConfig(object):
@lru_cache(maxsize=2048)
def __init__(self,fileName): #*args,**kwargs):
self._configs = Configparser.Configparser(fileName) #kwargs['filename'])
self._models = self._configs.getConfigElement('model','keys').split(sep=',')
self._key = {}
self._val = {}
self._inputPorts = {}
self.loadSection().setInputPorts()
@lru_cache(maxsize=2048)
def loadSection(self):
for kv in self._models:
for i in (self._configs.getConfigSection('model_' + kv)):
self._val [i[0]] = i[1]
self._key [kv] = copy.deepcopy(self._val)
return self
@lru_cache(maxsize=2048)
def getModels(self):
return list(filter(lambda x:x != 'connection',self._models))
@lru_cache(maxsize=2048)
def getConnection(self):
return list(filter(lambda x:x != 'connection',self._models))
@lru_cache(maxsize=2048)
def getModelAttributes(self,model):
return self._key [model]
@lru_cache(maxsize=2048)
def getModelInputPorts(self,model):
return self.getInputPorts().get(model)
@lru_cache(maxsize=2048)
def getInputPorts(self):
return self._inputPorts
@lru_cache(maxsize=2048)
def setInputPorts(self):
for model,property in self._key.items():
for port in list(filter(lambda x:x != '',property['OnSuccess'].split(',') + property['OnFailure'].split(','))):
if (not self._inputPorts.get(port)):
self._inputPorts [port] = [model]
else:
self._inputPorts [port] = self._inputPorts.get(port) + [model]
mc=ModelConfig('models.conf')
mc.loadSection()
print(mc.getConnection())
#mc.setInputPorts()
#print(mc.getModelInputPorts('print'))
#mc.loadSection.cache_info()
#print(mc.getSection('input'))
#print(mc.getSection.cache_info())
#mc.loadSection()
#print(mc.loadSection.cache_info())
#print(mc.getSection('input'))
#print(mc.getSection.cache_info())
#mc.loadSection()
#print(mc.loadSection.cache_info())
#print(mc.getSection('input'))
#print(mc.getSection.cache_info())