|
Gaudi Framework, version v23r3 |
| Home | Generated: Thu Jun 28 2012 |
Public Member Functions | |
| def | __init__ |
| def | errors |
| def | warnings |
| def | check |
| def | merge |
Public Attributes | |
| posActions | |
| separator | |
| report | |
| varNames | |
| realVariables | |
| variables | |
| output | |
| file | |
Private Member Functions | |
| def | _processVars |
| def | _checkVariable |
| def | _loadVariables |
This class is for checking and merging XML files. Variables are stored in a double dictionary with keys of names and then actions.
Definition at line 175 of file xmlModule.py.
| def EnvConfig::xmlModule::XMLOperations::__init__ | ( | self, | |
separator = ':', |
|||
reportLevel = 0, |
|||
reportOutput = False |
|||
| ) |
Definition at line 180 of file xmlModule.py.
00180 :', reportLevel = 0, reportOutput = False): 00181 self.posActions = ['append','prepend','set','unset', 'remove', 'remove-regexp', 'declare'] 00182 self.separator = separator 00183 self.report = Report(reportLevel, reportOutput = reportOutput) 00184
| def EnvConfig::xmlModule::XMLOperations::_checkVariable | ( | self, | |
| varName, | |||
| action, | |||
| local, | |||
| value, | |||
| nodeNum | |||
| ) | [private] |
Tries to add to variables dict, checks for errors during process
Definition at line 254 of file xmlModule.py.
00255 : 00256 '''Tries to add to variables dict, checks for errors during process''' 00257 00258 if varName not in self.variables: 00259 self.variables[varName] = [] 00260 self.variables[varName].append(action) 00261 00262 '''If variable is in dict, check if this is not an unset command''' 00263 elif action == 'unset': 00264 if 'unset' in self.variables[varName]: 00265 self.report.addWarn('Multiple "unset" actions found for variable: "'+varName+'".', varName, 'multiple unset','', 'checkVariable') 00266 if not('unset' in self.variables[varName] and len(self.variables[varName]) == 1): 00267 self.report.addError('Node '+str(nodeNum)+': "unset" action found for variable "'+varName+'" after previous command(s). Any previous commands are overridden.', varName, 'unset overwrite') 00268 00269 '''or set command''' 00270 elif action == 'set': 00271 if len(self.variables[varName]) == 1 and 'unset' in self.variables[varName]: 00272 self.report.addWarn('Node '+str(nodeNum)+': "set" action found for variable "'+varName+'" after unset. Can be merged to one set only.') 00273 else: 00274 self.report.addError('Node '+str(nodeNum)+': "set" action found for variable "'+varName+'" after previous command(s). Any previous commands are overridden.', varName, 'set overwrite') 00275 if 'set' in self.variables[varName]: 00276 self.report.addWarn('Multiple "set" actions found for variable: "'+varName+'".', varName, 'multiple set','', 'checkVariable') 00277 00278 if action not in self.variables[varName]: 00279 self.variables[varName].append(action) 00280 00281 try: 00282 if action == 'remove-regexp': 00283 action = 'remove_regexp' 00284 eval('(self.realVariables[varName]).'+action+'(value)') 00285 except Variable.EnvironmentError as e: 00286 if e.code == 'undefined': 00287 self.report.addWarn('Referenced variable "' +e.val+ '" is not defined.') 00288 elif e.code == 'ref2var': 00289 self.report.addError('Reference to list from the middle of string.') 00290 elif e.code == 'redeclaration': 00291 self.report.addError('Redeclaration of variable "'+e.val+'".') 00292 else: 00293 self.report.addError('Unknown environment error occured.') 00294
| def EnvConfig::xmlModule::XMLOperations::_loadVariables | ( | self, | |
| fileName | |||
| ) | [private] |
loads XML file for input variables
Definition at line 295 of file xmlModule.py.
00296 : 00297 '''loads XML file for input variables''' 00298 XMLfile = XMLFile() 00299 variables = XMLfile.variable(fileName) 00300 for variable in variables: 00301 undeclared = False 00302 if variable[0] == '': 00303 raise RuntimeError('Empty variable or local name is not allowed.') 00304 00305 if variable[0] not in self.realVariables.keys(): 00306 if variable[1] != 'declare': 00307 self.report.addInfo('Node '+str(variable[4])+': Variable '+variable[0]+' is used before declaration. Treated as an unlocal list furthermore.') 00308 undeclared = True 00309 self.realVariables[variable[0]] = Variable.List(variable[0], False, report=self.report) 00310 else: 00311 self.varNames.append(variable[0]) 00312 if variable[2] == 'list': 00313 self.realVariables[variable[0]] = Variable.List(variable[0], variable[3], report=self.report) 00314 else: 00315 self.realVariables[variable[0]] = Variable.Scalar(variable[0], variable[3], report=self.report) 00316 if not undeclared: 00317 continue 00318 00319 if variable[1] not in self.posActions: 00320 self.report.addError('Node '+str(variable[4])+': Action "'+variable[1]+'" which is not implemented found. Variable "'+variable[0]+'".', variable[0], variable[1] ,variable[2]) 00321 continue 00322 00323 else: 00324 if variable[1] == 'declare': 00325 self.report.addError('Node '+str(variable[4])+': Variable '+variable[0]+' is redeclared.') 00326 else: 00327 self._checkVariable(variable[0], variable[1], self.realVariables[variable[0]].local, (str)(variable[2]), variable[4])
| def EnvConfig::xmlModule::XMLOperations::_processVars | ( | self, | |
| variables | |||
| ) | [private] |
Definition at line 238 of file xmlModule.py.
00239 : 00240 for variable in variables: 00241 if variable[1] == 'declare': 00242 if variable[0] in self.variables.keys(): 00243 if variable[2].lower() != self.variables[variable[0]][0]: 00244 raise Variable.EnvironmentError(variable[0], 'redeclaration') 00245 else: 00246 if variable[3].lower() != self.variables[variable[0]][1]: 00247 raise Variable.EnvironmentError(variable[0], 'redeclaration') 00248 else: 00249 self.file.writeVar(variable[0], 'declare', '', variable[2], variable[3]) 00250 self.variables[variable[0]] = [variable[2].lower(), variable[3].lower()] 00251 else: 00252 self.file.writeVar(variable[0], variable[1], variable[2]) 00253
| def EnvConfig::xmlModule::XMLOperations::check | ( | self, | |
| xmlFile | |||
| ) |
Runs a check through file First check is made on wrong action parameter. All valid actions are checked after and duplicated variables as well.
Definition at line 191 of file xmlModule.py.
00192 : 00193 '''Runs a check through file 00194 00195 First check is made on wrong action parameter. 00196 All valid actions are checked after and duplicated variables as well. 00197 ''' 00198 #self.local = Variable.Local() 00199 self.varNames = [] 00200 self.realVariables = {} 00201 self.variables = {} 00202 00203 '''load variables and resolve references to locals and then variables''' 00204 self._loadVariables(xmlFile) 00205 00206 '''report''' 00207 if (self.warnings() > 0 or self.errors() > 0): 00208 self.report.addInfo('Encountered '+ (str)(self.warnings()) +' warnings and ' + (str)(self.errors()) + ' errors.') 00209 return [self.warnings(), self.errors()] 00210 else: 00211 return True 00212 00213 self.report.closeFile() 00214
| def EnvConfig::xmlModule::XMLOperations::errors | ( | self ) |
Definition at line 185 of file xmlModule.py.
| def EnvConfig::xmlModule::XMLOperations::merge | ( | self, | |
| xmlDoc1, | |||
| xmlDoc2, | |||
outputFile = '', |
|||
reportCheck = False |
|||
| ) |
Merges two files together. Files are checked first during variables loading process. Second file is processed first, then the first file and after that they are merged together.
Definition at line 215 of file xmlModule.py.
00216 : 00217 '''Merges two files together. Files are checked first during variables loading process. 00218 00219 Second file is processed first, then the first file and after that they are merged together. 00220 ''' 00221 self.output = outputFile 00222 self.file = XMLFile() 00223 self.variables = {} 00224 00225 variables = self.file.variable(xmlDoc1) 00226 self._processVars(variables) 00227 variables = self.file.variable(xmlDoc2) 00228 self._processVars(variables) 00229 00230 if not reportCheck: 00231 self.report.level = 5 00232 00233 self.file.writeToFile(outputFile) 00234 00235 self.report.addInfo('Files merged. Running check on the result.') 00236 self.check(self.output) 00237 self.report.closeFile()
| def EnvConfig::xmlModule::XMLOperations::warnings | ( | self ) |
Definition at line 188 of file xmlModule.py.
Definition at line 218 of file xmlModule.py.
Definition at line 218 of file xmlModule.py.
Definition at line 180 of file xmlModule.py.
Definition at line 195 of file xmlModule.py.
Definition at line 180 of file xmlModule.py.
Definition at line 180 of file xmlModule.py.
Definition at line 195 of file xmlModule.py.
Definition at line 195 of file xmlModule.py.