-
Notifications
You must be signed in to change notification settings - Fork 37
/
readCfgFile.py
108 lines (90 loc) · 3.76 KB
/
readCfgFile.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
from buildCfg import *
from groupCfg import *
class readCfgFileBase(baseCfg):
def __init__(self, name, file):
self._section = ConfigObj(infile=file, stringify=True)
super(readCfgFileBase, self).__init__(name, self._section, None)
self._subSectionType = {}
self._validSection = ['build', 'testgroup']
def _readSubSection(self):
for k, v in getSections(self._section).items():
if self._checkSubSection(k) and k in self._subSectionType:
self._subSection[k] = self._subSectionType[k](k, v, self)
self._subSection[k].parse()
def _checkSubSection(self, key):
if key not in self._validSection:
raise ParseError('[%s] is unknown section' % key)
return True
class readBuildCfgFile(readCfgFileBase):
def __init__(self, file):
super(readBuildCfgFile, self).__init__('readBuildCfgFile', file)
self._subSectionType = {'build': buildCfg}
self.parse()
@property
def build(self):
if 'build' in self.subSection:
return self.subSection['build']
class readGroupCfgFile(readCfgFileBase):
def __init__(self, file):
super(readGroupCfgFile, self).__init__('readGroupCfgFile', file)
self._subSectionType = {'testgroup': groupCfg}
self.parse()
self.validBuild = []
self._tests = {}
@property
def testGroup(self):
if 'testgroup' in self.subSection:
return self.subSection['testgroup']
def getTests(self, groupName):
groupSection = self.testGroup.getGroup(groupName)
globalBuild = groupSection.buildOption
globalArgs = groupSection.argsOption
globalTests = groupSection.testsOption
print('1', globalBuild)
print(groupSection.argsOption)
print(groupSection.testsOption)
print(groupSection.include)
if globalBuild:
self.validBuild.append(globalBuild)
if globalTests:
self._tests[groupName] = globalTests
if groupSection.include:
print('debug point has include')
for incGroup in groupSection.incGroups:
print('11', incGroup.buildOption)
print(incGroup.argsOption)
print(incGroup.testsOption)
if incGroup.testsOption:
self._tests[incGroup.name] = incGroup.testsOption
self.setValidBuild(globalBuild, incGroup.buildOption)
self.checkBuild(self.validBuild, groupName)
def setValidBuild(self, globalBuild, subBuild):
if globalBuild and subBuild and globalBuild != subBuild:
self.validBuild.append(globalBuild)
elif subBuild and not globalBuild:
self.validBuild.append(subBuild)
elif globalBuild and not subBuild:
self.validBuild.append(globalBuild)
def checkBuild(self, buildList, groupName):
buildSet = set(buildList)
print("debug point valid build", buildSet)
if len(buildSet) != 1:
raise ValueError(('group %s has included subgroup is must be in same build' % groupName))
if __name__ == '__main__':
#config = readBuildCfgFile(defaultBuildFile())
#print(config.build.simOption)
#print(config.build.compileOption)
#print(config.build.getBuild('').name)
#print(config.build.getBuild('dla_fpga').name)
config = readGroupCfgFile(defaultGroupFile())
config.getTests('v1_regr')
#config.getTests('top_regr')
#for v in config.testgroup.subSection.values():
# print(v.include)
# print(v.name)
#print(v.buildOption)
#print(v.argsOption)
#print(v.testsOption)
#print('haha', v.include)
#for include in v.include:
# print(config.getGroup(include).testsOption)