Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012
Public Member Functions | Public Attributes | Private Member Functions

EnvConfig::xmlModule::XMLOperations Class Reference

List of all members.

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

Detailed Description

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 194 of file xmlModule.py.


Constructor & Destructor Documentation

def EnvConfig::xmlModule::XMLOperations::__init__ (   self,
  separator = ':',
  reportLevel = 0,
  reportOutput = False 
)

Definition at line 199 of file xmlModule.py.

00199                                   :', reportLevel = 0, reportOutput = False):
00200         self.posActions = ['append','prepend','set','unset', 'remove', 'remove-regexp', 'declare']
00201         self.separator = separator
00202         self.report = Report(reportLevel, reportOutput = reportOutput)
00203 

Member Function Documentation

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 273 of file xmlModule.py.

00274                                                                     :
00275         '''Tries to add to variables dict, checks for errors during process'''
00276 
00277         if varName not in self.variables:
00278             self.variables[varName] = []
00279             self.variables[varName].append(action)
00280 
00281         # If variable is in dict, check if this is not an unset command
00282         elif action == 'unset':
00283             if 'unset' in self.variables[varName]:
00284                 self.report.addWarn('Multiple "unset" actions found for variable: "'+varName+'".', varName, 'multiple unset','', 'checkVariable')
00285             if not('unset' in self.variables[varName] and len(self.variables[varName]) == 1):
00286                 self.report.addError('Node '+str(nodeNum)+': "unset" action found for variable "'+varName+'" after previous command(s). Any previous commands are overridden.', varName, 'unset overwrite')
00287 
00288         # or set command
00289         elif action == 'set':
00290             if len(self.variables[varName]) == 1 and 'unset' in self.variables[varName]:
00291                 self.report.addWarn('Node '+str(nodeNum)+': "set" action found for variable "'+varName+'" after unset. Can be merged to one set only.')
00292             else:
00293                 self.report.addError('Node '+str(nodeNum)+': "set" action found for variable "'+varName+'" after previous command(s). Any previous commands are overridden.', varName, 'set overwrite')
00294                 if 'set' in self.variables[varName]:
00295                     self.report.addWarn('Multiple "set" actions found for variable: "'+varName+'".', varName, 'multiple set','', 'checkVariable')
00296 
00297         if action not in self.variables[varName]:
00298             self.variables[varName].append(action)
00299 
00300         try:
00301             if action == 'remove-regexp':
00302                 action = 'remove_regexp'
00303             eval('(self.realVariables[varName]).'+action+'(value)')
00304         except Variable.EnvironmentError as e:
00305             if e.code == 'undefined':
00306                 self.report.addWarn('Referenced variable "' +e.val+ '" is not defined.')
00307             elif e.code == 'ref2var':
00308                 self.report.addError('Reference to list from the middle of string.')
00309             elif e.code == 'redeclaration':
00310                 self.report.addError('Redeclaration of variable "'+e.val+'".')
00311             else:
00312                 self.report.addError('Unknown environment error occured.')
00313 

def EnvConfig::xmlModule::XMLOperations::_loadVariables (   self,
  fileName 
) [private]
loads XML file for input variables

Definition at line 314 of file xmlModule.py.

00315                                       :
00316         '''loads XML file for input variables'''
00317         XMLfile = XMLFile()
00318         variables = XMLfile.variable(fileName)
00319         for i, (action, (arg1, arg2, arg3))  in enumerate(variables):
00320             undeclared = False
00321             if arg1 == '':
00322                 raise RuntimeError('Empty variable or local name is not allowed.')
00323 
00324             if arg1 not in self.realVariables.keys():
00325                 if action != 'declare':
00326                     self.report.addInfo('Node '+str(i)+': Variable '+arg1+' is used before declaration. Treated as an unlocal list furthermore.')
00327                     undeclared = True
00328                     self.realVariables[arg1] = Variable.List(arg1, False, report=self.report)
00329                 else:
00330                     self.varNames.append(arg1)
00331                     if arg2 == 'list':
00332                         self.realVariables[arg1] = Variable.List(arg1, arg3, report=self.report)
00333                     else:
00334                         self.realVariables[arg1] = Variable.Scalar(arg1, arg3, report=self.report)
00335                     if not undeclared:
00336                         continue
00337 
00338             if action not in self.posActions:
00339                 self.report.addError('Node '+str(i)+': Action "'+action+'" which is not implemented found. Variable "'+arg1+'".', arg1, action, arg2)
00340                 continue
00341 
00342             else:
00343                 if action == 'declare':
00344                     self.report.addError('Node '+str(i)+': Variable '+arg1+' is redeclared.')
00345                 else:
00346                     self._checkVariable(arg1, action, self.realVariables[arg1].local, str(arg2), i)
def EnvConfig::xmlModule::XMLOperations::_processVars (   self,
  variables 
) [private]

Definition at line 257 of file xmlModule.py.

00258                                      :
00259         for action, (arg1, arg2, arg3) in variables:
00260             if action == 'declare':
00261                 if arg1 in self.variables.keys():
00262                     if arg2.lower() != self.variables[arg1][0]:
00263                         raise Variable.EnvironmentError(arg1, 'redeclaration')
00264                     else:
00265                         if arg3.lower() != self.variables[arg1][1]:
00266                             raise Variable.EnvironmentError(arg1, 'redeclaration')
00267                 else:
00268                     self.file.writeVar(arg1, 'declare', '', arg2, arg3)
00269                     self.variables[arg1] = [arg2.lower(), arg3.lower()]
00270             else:
00271                 self.file.writeVar(arg1, action, arg2)
00272 

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 210 of file xmlModule.py.

00211                             :
00212         '''Runs a check through file
00213 
00214         First check is made on wrong action parameter.
00215         All valid actions are checked after and duplicated variables as well.
00216         '''
00217         #self.local = Variable.Local()
00218         self.varNames = []
00219         self.realVariables = {}
00220         self.variables = {}
00221 
00222         # load variables and resolve references to locals and then variables
00223         self._loadVariables(xmlFile)
00224 
00225         # report
00226         if (self.warnings() > 0 or self.errors() > 0):
00227             self.report.addInfo('Encountered '+ (str)(self.warnings()) +' warnings and ' + (str)(self.errors()) + ' errors.')
00228             return [self.warnings(), self.errors()]
00229         else:
00230             return True
00231 
00232         self.report.closeFile()
00233 

def EnvConfig::xmlModule::XMLOperations::errors (   self )

Definition at line 204 of file xmlModule.py.

00205                     :
00206         return self.report.numErrors()

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 234 of file xmlModule.py.

00235                                                                            :
00236         '''Merges two files together. Files are checked first during variables loading process.
00237 
00238         Second file is processed first, then the first file and after that they are merged together.
00239         '''
00240         self.output = outputFile
00241         self.file = XMLFile()
00242         self.variables = {}
00243 
00244         variables = self.file.variable(xmlDoc1)
00245         self._processVars(variables)
00246         variables = self.file.variable(xmlDoc2)
00247         self._processVars(variables)
00248 
00249         if not reportCheck:
00250             self.report.level = 5
00251 
00252         self.file.writeToFile(outputFile)
00253 
00254         self.report.addInfo('Files merged. Running check on the result.')
00255         self.check(self.output)
00256         self.report.closeFile()

def EnvConfig::xmlModule::XMLOperations::warnings (   self )

Definition at line 207 of file xmlModule.py.

00208                       :
00209         return self.report.numWarnings()


Member Data Documentation

Definition at line 237 of file xmlModule.py.

Definition at line 237 of file xmlModule.py.

Definition at line 199 of file xmlModule.py.

Definition at line 214 of file xmlModule.py.

Definition at line 199 of file xmlModule.py.

Definition at line 199 of file xmlModule.py.

Definition at line 214 of file xmlModule.py.

Definition at line 214 of file xmlModule.py.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:53 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004