annotate commons/core/checker/ConfigChecker.py @ 60:90f4b29d884f

Uploaded
author m-zytnicki
date Fri, 21 Feb 2014 08:32:36 -0500
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 # Copyright INRA (Institut National de la Recherche Agronomique)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 # http://www.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # http://urgi.versailles.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 import re
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import sys
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from commons.core.utils.RepetConfigParser import RepetConfigParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 from commons.core.checker.ConfigValue import ConfigValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 from commons.core.checker.IChecker import IChecker
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from commons.core.checker.RepetException import RepetException
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 from commons.core.utils.FileUtils import FileUtils
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 class Rule(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 def __init__(self, mandatory= False, isPattern=False, type="", set=(), help =""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 self.mandatory = mandatory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 self.isPattern = isPattern
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 self.type = type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 self.set = set
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 self.help = help
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 class ConfigRules(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 def __init__(self, configName = "", configDescription = ""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 self.configName = configName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 self.configDescription = configDescription
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 self.dRules4Sections={}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 def _addRule(self, section, option="DEFAULT", mandatory=False, isPattern=False, type="", set=(), help =""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 if not self.dRules4Sections.has_key(section):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 self.dRules4Sections[section] = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 self.dRules4Sections[section][option]=Rule(mandatory, isPattern, type.lower(), set)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 def addRuleSection(self, section, mandatory=False, isPattern=False, help = ""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 self._addRule(section = section, option = "DEFAULT", mandatory = mandatory, isPattern = isPattern, help = "")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 def addRuleOption(self, section, option, mandatory=False, isPattern=False, type="", set=(), help = ""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 self._addRule(section = section, option = option, mandatory = mandatory, isPattern = isPattern, type = type, set=set , help = "")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 def isSectionMandatory(self, section):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 if self.dRules4Sections.has_key(section):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 if self.dRules4Sections[section].has_key("DEFAULT"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 return self.dRules4Sections[section]["DEFAULT"].mandatory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 def isOptionMandatory(self, section, option):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 if self.dRules4Sections.has_key(section):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 if self.dRules4Sections[section].has_key(option):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 return self.dRules4Sections[section][option].mandatory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 def getRule(self, section, option):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 if self.dRules4Sections.has_key(section):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 if self.dRules4Sections[section].has_key(option):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 return self.dRules4Sections[section][option]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 return None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 class ConfigChecker(IChecker):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 def __init__ (self, cfgFileName, iCfgRules):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 self._configFileName = cfgFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 self._iConfigRules = iCfgRules
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 self._iRawConfig = ConfigValue()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 self._iExtendedConfigRules = ConfigRules()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 def readConfigFile(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 iConfig = RepetConfigParser()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 iConfig.readfp(open(self._configFileName))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 return iConfig
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 # TODO USE OF CONFIG ERROR
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 # if DuplicateSectionError:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 # raise Exception ("Duplicate section exist in config file %s" %(self._configFileName ))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 except :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 raise RepetException ("Unexpected error: %s" % sys.exc_info()[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 def setRawConfig(self, iConfig ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 for sectionName in iConfig.sections():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 for optionName in iConfig.options(sectionName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 optionValue = iConfig.get(sectionName, optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 self._iRawConfig.set(sectionName, optionName, optionValue)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 def getOptionValueAccordingRule(self, iConfig, sectionName, optionName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 optionRule = self._iExtendedConfigRules.getRule(sectionName, optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 if optionRule == None :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 return iConfig.get(sectionName, optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 if optionRule.type == "int":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 optionValue = iConfig.getint(sectionName, optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 elif optionRule.type == "float":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 optionValue = iConfig.getfloat(sectionName, optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 elif optionRule.type == "bool" or optionRule.type == "boolean":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 optionValue = iConfig.getboolean(sectionName, optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 optionValue = iConfig.get(sectionName, optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 if optionRule.set!=() and not(optionValue in optionRule.set):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 #TODO : test and fix
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 raise RepetException ("value must be in %s " % set.__repr__())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 return optionValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 def setConfig(self, iConfig ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 config = ConfigValue()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 valueErr = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 for sectionName in iConfig.sections():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 for optionName in iConfig.options(sectionName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 optionValue = self.getOptionValueAccordingRule(iConfig, sectionName, optionName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 config.set(sectionName, optionName, optionValue)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 except RepetException, re :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 #TODO : test and fix
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 valueErr += "\n - [%s]: %s %s" % re.getMessage()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 if valueErr == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 self._iRawConfig = config
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 raise RepetException ("Following errors occurs:%s\n" %valueErr)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 def checkIfExistsConfigFile (self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 if not (FileUtils.isRessourceExists(self._configFileName)):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 raise RepetException("CONFIG FILE not found - '%s'" % self._configFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 def checkMandatorySections (self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 missingSection = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 for sectionName in self._iExtendedConfigRules.dRules4Sections.keys():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 if self._iExtendedConfigRules.isSectionMandatory(sectionName) and not self._iRawConfig.has_section(sectionName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 missingSection += "\n - %s" %(sectionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 if missingSection != "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 raise RepetException ("Error in configuration file %s, following sections are missing:%s\n" % (self._configFileName, missingSection))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 def checkMandatoryOptions (self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 missingOption = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 for sectionName in self._iExtendedConfigRules.dRules4Sections.keys():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 if self._iExtendedConfigRules.isSectionMandatory(sectionName) or self._iRawConfig.has_section(sectionName) :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 dRules4OptionsOfThisSection = self._iExtendedConfigRules.dRules4Sections[sectionName]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 for optionName in dRules4OptionsOfThisSection.keys():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 if optionName != "DEFAULT" and self._iExtendedConfigRules.isOptionMandatory(sectionName, optionName) and not self._iRawConfig.has_option(sectionName, optionName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 missingOption += "\n - [%s]: %s" % (sectionName, optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 if missingOption != "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 raise RepetException ("Error in configuration file %s, following options are missing: %s\n" % (self._configFileName, missingOption))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 def getSectionNamesAccordingPatternRules (self, sectionWordOrPattern, isPattern):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 lSectionsFoundAccordingPatternRules=[]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 if isPattern == False:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 if self._iRawConfig.has_section(sectionWordOrPattern):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 lSectionsFoundAccordingPatternRules.append(sectionWordOrPattern)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 for sectionName in self._iRawConfig.sections():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 if re.search(sectionWordOrPattern, sectionName, re.IGNORECASE):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 lSectionsFoundAccordingPatternRules.append(sectionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 return lSectionsFoundAccordingPatternRules
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 def getOptionsNamesAccordingPatternRules(self, sectionName, optionWordOrPattern, isPattern):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 lOptionsFoundAccordingPatternRules=[]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 if isPattern == False:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 if self._iRawConfig.has_option(sectionName, optionWordOrPattern):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 lOptionsFoundAccordingPatternRules.append(optionWordOrPattern)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 else :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 for optionName in self._iRawConfig.options(sectionName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 if re.search(optionWordOrPattern, optionName, re.IGNORECASE)!= None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 lOptionsFoundAccordingPatternRules.append(optionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 return lOptionsFoundAccordingPatternRules
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 def extendConfigRulesWithPatternRules(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 for sectionName in self._iConfigRules.dRules4Sections.keys():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 dRules4OptionsOfThisSection = self._iConfigRules.dRules4Sections[sectionName]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 lRawSections=[]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 if dRules4OptionsOfThisSection.has_key("DEFAULT"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 mandatorySection = dRules4OptionsOfThisSection["DEFAULT"].mandatory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 isPatternSection = dRules4OptionsOfThisSection["DEFAULT"].isPattern
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 lRawSections=self.getSectionNamesAccordingPatternRules(sectionName, isPatternSection)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 for rawSectionName in lRawSections:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 self._iExtendedConfigRules.addRuleSection(rawSectionName, "DEFAULT", mandatorySection )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 if mandatorySection and (len(lRawSections)==0):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 self._iExtendedConfigRules.addRuleSection(sectionName, "DEFAULT", mandatorySection )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 lRawSections.append(sectionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 for optionName in dRules4OptionsOfThisSection.keys():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 setOption = dRules4OptionsOfThisSection[optionName].set
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 isPatternOption = dRules4OptionsOfThisSection[optionName].isPattern
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 mandatoryOption = dRules4OptionsOfThisSection[optionName].mandatory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 typeOption = dRules4OptionsOfThisSection[optionName].type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 if optionName != "DEFAULT":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 for rawSectionName in lRawSections:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 lRawOptions=self.getOptionsNamesAccordingPatternRules(rawSectionName, optionName, isPatternOption)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 for rawOptionName in lRawOptions:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 self._iExtendedConfigRules.addRuleOption(rawSectionName, rawOptionName, mandatoryOption, False, typeOption, setOption)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 if mandatoryOption and (len(lRawOptions)==0):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 self._iExtendedConfigRules.addRuleOption(rawSectionName, optionName, mandatoryOption, False, typeOption, setOption)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 def getConfig(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 self.checkIfExistsConfigFile()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 iConfig = self.readConfigFile()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 self.setRawConfig(iConfig)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 self.extendConfigRulesWithPatternRules()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 self.checkMandatorySections()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 self.checkMandatoryOptions()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 self.setConfig(iConfig)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 return self._iRawConfig