Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
EnvConfig.xmlModule.XMLFile Class Reference

Public Member Functions

def __init__
 
def variable
 
def resetWriter
 
def writeToFile
 
def writeVar
 

Public Attributes

 xmlResult
 
 declaredVars
 
 logger
 

Detailed Description

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

Definition at line 14 of file xmlModule.py.

Constructor & Destructor Documentation

def EnvConfig.xmlModule.XMLFile.__init__ (   self)

Definition at line 17 of file xmlModule.py.

17 
18  def __init__(self):
19  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'
20  self.declaredVars = []
21  logConf = os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + '/log.conf')
22  if not logging.getLogger('envLogger').handlers and os.path.exists(logConf):
23  logging.config.fileConfig(logConf)
24  self.logger = logging.getLogger('envLogger')

Member Function Documentation

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

Definition at line 98 of file xmlModule.py.

98 
99  def resetWriter(self):
100  '''resets the buffer of writer'''
101  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'
102  self.declaredVars = []
def EnvConfig.xmlModule.XMLFile.variable (   self,
  path,
  namespace = 'EnvSchema',
  name = None 
)
Returns list containing name of variable, action and value.

@param path: a file name or a file-like object

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

Definition at line 25 of file xmlModule.py.

25 
26  def variable(self, path, namespace='EnvSchema', name=None):
27  '''Returns list containing name of variable, action and value.
28 
29  @param path: a file name or a file-like object
30 
31  If no name given, returns list of lists of all variables and locals(instead of action 'local' is filled).
32  '''
33  isFilename = type(path) is str
34  if isFilename:
35  checksum = md5()
36  checksum.update(open(path, 'rb').read())
37  checksum = checksum.digest()
38 
39  cpath = path + "c" # preparsed file
40  try:
41  f = open(cpath, 'rb')
42  oldsum, data = load(f)
43  if oldsum == checksum:
44  return data
45  except IOError:
46  pass
47  except EOFError:
48  pass
49 
50  caller = path
51  else:
52  caller = None
53 
54  # Get file
55  doc = minidom.parse(path)
56  if namespace == '':
57  namespace = None
58 
59  ELEMENT_NODE = minidom.Node.ELEMENT_NODE
60  # Get all variables
61  nodes = doc.getElementsByTagNameNS(namespace, "config")[0].childNodes
62  variables = []
63  for node in nodes:
64  # if it is an element node
65  if node.nodeType == ELEMENT_NODE:
66  action = str(node.localName)
67 
68  if action == 'include':
69  if node.childNodes:
70  value = str(node.childNodes[0].data)
71  else:
72  value = ''
73  variables.append((action, (value, caller, str(node.getAttribute('hints')))))
74 
75  else:
76  varname = str(node.getAttribute('variable'))
77  if name and varname != name:
78  continue
79 
80  if action == 'declare':
81  variables.append((action, (varname, str(node.getAttribute('type')), str(node.getAttribute('local')))))
82  else:
83  if node.childNodes:
84  value = str(node.childNodes[0].data)
85  else:
86  value = ''
87  variables.append((action, (varname, value, None)))
88 
89  if isFilename:
90  try:
91  f = open(cpath, 'wb')
92  dump((checksum, variables), f, protocol=2)
93  f.close()
94  except IOError:
95  pass
96  return variables
97 
def EnvConfig.xmlModule.XMLFile.writeToFile (   self,
  outputFile = None 
)
Finishes the XML input and writes XML to file.

Definition at line 103 of file xmlModule.py.

104  def writeToFile(self, outputFile=None):
105  '''Finishes the XML input and writes XML to file.'''
106  if outputFile is None:
107  raise IOError("No output file given")
108  self.xmlResult += '</env:config>'
109 
110  doc = minidom.parseString(self.xmlResult)
111  with open(outputFile, "w") as f:
112  f.write( doc.toxml() )
113 
114  f.close()
115  return outputFile
def EnvConfig.xmlModule.XMLFile.writeVar (   self,
  varName,
  action,
  value,
  vartype = 'list',
  local = False 
)
Writes a action to a file. Declare undeclared elements (non-local list is default type).

Definition at line 116 of file xmlModule.py.

117  def writeVar(self, varName, action, value, vartype='list', local=False):
118  '''Writes a action to a file. Declare undeclared elements (non-local list is default type).'''
119  if action == 'declare':
120  self.xmlResult += '<env:declare variable="'+varName+'" type="'+ vartype.lower() +'" local="'+(str(local)).lower()+'" />\n'
121  self.declaredVars.append(varName)
122  return
123 
124  if varName not in self.declaredVars:
125  self.xmlResult += '<env:declare variable="'+varName+'" type="'+ vartype +'" local="'+(str(local)).lower()+'" />\n'
126  self.declaredVars.append(varName)
127  self.xmlResult += '<env:'+action+' variable="'+ varName +'">'+value+'</env:'+action+'>\n'
128 

Member Data Documentation

EnvConfig.xmlModule.XMLFile.declaredVars

Definition at line 19 of file xmlModule.py.

EnvConfig.xmlModule.XMLFile.logger

Definition at line 23 of file xmlModule.py.

EnvConfig.xmlModule.XMLFile.xmlResult

Definition at line 18 of file xmlModule.py.


The documentation for this class was generated from the following file:
Generated at Wed Nov 28 2012 12:17:35 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004