Gaudi Framework, version v23r3

Home   Generated: Thu Jun 28 2012
Public Member Functions | Public Attributes

EnvConfig::xmlModule::XMLFile Class Reference

List of all members.

Public Member Functions

def __init__
def variable
def resetWriter
def writeToFile
def writeVar

Public Attributes

 xmlResult
 declaredVars
 logger
 doc

Detailed Description

Takes care of XML file operations such as reading and writing.

Definition at line 12 of file xmlModule.py.


Constructor & Destructor Documentation

def EnvConfig::xmlModule::XMLFile::__init__ (   self )

Definition at line 15 of file xmlModule.py.

00016                       :
00017         self.xmlResult = '<?xml version="1.0" encoding="UTF-8"?><env:config xmlns:env="EnvSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="EnvSchema ./EnvSchema.xsd ">\n'
00018         self.declaredVars = []
00019         logConf = os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + '/log.conf')
00020         if not logging.getLogger('envLogger').handlers and os.path.exists(logConf):
00021             logging.config.fileConfig(logConf)
00022         self.logger = logging.getLogger('envLogger')
00023 


Member Function Documentation

def EnvConfig::xmlModule::XMLFile::resetWriter (   self )
resets the buffer of writer

Definition at line 60 of file xmlModule.py.

00061                          :
00062         '''resets the buffer of writer'''
00063         self.xmlResult = '<?xml version="1.0" encoding="UTF-8"?><env:config xmlns:env="EnvSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="EnvSchema ./EnvSchema.xsd ">\n'
00064         self.declaredVars = []

def EnvConfig::xmlModule::XMLFile::variable (   self,
  path,
  namespace = 'EnvSchema',
  name = '' 
)
Returns list containing name of variable, action and value

If no name given, returns list of lists of all variables and locals(instead of action 'local' is filled).

Definition at line 24 of file xmlModule.py.

00025                                                             :
00026         '''Returns list containing name of variable, action and value
00027 
00028         If no name given, returns list of lists of all variables and locals(instead of action 'local' is filled).
00029         '''
00030         if not os.path.isfile(path):
00031             raise IOError('No such file.')
00032         '''Get file'''
00033         self.doc = minidom.parse(path)
00034         if namespace == '':
00035             namespace = None
00036 
00037         '''Get all variables'''
00038         nodes = self.doc.getElementsByTagNameNS(namespace, "config")[0].childNodes
00039         variables = []
00040         nodeNum = 0
00041         for node in nodes:
00042             '''if it is an element node'''
00043             if node.nodeType == 1:
00044                 nodeNum += 1
00045                 if name != '':
00046                     if node.getAttribute('variable') != name:
00047                         continue
00048 
00049                 if node.localName == 'declare':
00050                     variables.append([node.getAttribute('variable'), 'declare', node.getAttribute('type'), node.getAttribute('local'), nodeNum])
00051                 else:
00052                     if len(node.childNodes) > 0:
00053                         value = node.childNodes[0].data
00054                     else:
00055                         value = ''
00056                     variables.append([node.getAttribute('variable'), node.localName, value, '' , nodeNum])
00057 
00058         return variables
00059 

def EnvConfig::xmlModule::XMLFile::writeToFile (   self,
  outputFile = '' 
)
Finishes the XML input and writes XML to file.

Definition at line 65 of file xmlModule.py.

00066                                           :
00067         '''Finishes the XML input and writes XML to file.'''
00068         if(outputFile == ''):
00069             raise IOError("No output file given")
00070         self.xmlResult += '</env:config>'
00071 
00072         doc = minidom.parseString(self.xmlResult)
00073         with open(outputFile, "w") as f:
00074             f.write( doc.toxml() )
00075 
00076         f.close()
00077         return outputFile

def EnvConfig::xmlModule::XMLFile::writeVar (   self,
  varName,
  action,
  value,
  type = 'list',
  local = 'false' 
)
Writes a action to a file. Declare undeclared elements (not local List is default type).

Definition at line 78 of file xmlModule.py.

00079                                                                           :
00080         '''Writes a action to a file. Declare undeclared elements (not local List is default type).'''
00081         if action == 'declare':
00082             self.xmlResult += '<env:declare variable="'+varName+'" type="'+ type.lower() +'" local="'+(str(local)).lower()+'" />\n'
00083             self.declaredVars.append(varName)
00084             return
00085 
00086         if varName not in self.declaredVars:
00087             self.xmlResult += '<env:declare variable="'+varName+'" type="'+ type +'" local="'+(str(local)).lower()+'" />\n'
00088             self.declaredVars.append(varName)
00089         self.xmlResult += '<env:'+action+' variable="'+ varName +'">'+value+'</env:'+action+'>\n'
00090 


Member Data Documentation

Definition at line 15 of file xmlModule.py.

Definition at line 27 of file xmlModule.py.

Definition at line 15 of file xmlModule.py.

Definition at line 15 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 Thu Jun 28 2012 12:30:18 for Gaudi Framework, version v23r3 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004