| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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
Inheritance diagram for EnvConfig.xmlModule.XMLFile:
[legend]
Collaboration diagram for EnvConfig.xmlModule.XMLFile:
[legend]

## Public Member Functions
def | __init__
def | variable
def | resetWriter
def | writeToFile
def | writeVar

## Public Attributes
| xmlResult
| declaredVars
| log

## 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.

15
16 def __init__(self):
17 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'
18 self.declaredVars = []
19 self.log = logging.getLogger('XMLFile')

## Member Function Documentation

def EnvConfig.xmlModule.XMLFile.resetWriter | ( |  | self | ) |

    resets the buffer of writer

Definition at line 100 of file xmlModule.py.

100
101 def resetWriter(self):
102 '''resets the buffer of writer'''
103 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'
104 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 20 of file xmlModule.py.

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

def EnvConfig.xmlModule.XMLFile.writeToFile | ( |  | self,
|  |  | outputFile = `None`
| ) |  |

    Finishes the XML input and writes XML to file.

Definition at line 105 of file xmlModule.py.

105
106 def writeToFile(self, outputFile=None):
107 '''Finishes the XML input and writes XML to file.'''
108 if outputFile is None:
109 raise IOError("No output file given")
110 self.xmlResult += '</env:config>'
111
112 doc = minidom.parseString(self.xmlResult)
113 with open(outputFile, "w") as f:
114 f.write( doc.toxml() )
115
116 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 117 of file xmlModule.py.

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

## Member Data Documentation

EnvConfig.xmlModule.XMLFile.declaredVars

Definition at line 17 of file xmlModule.py.

EnvConfig.xmlModule.XMLFile.log

Definition at line 18 of file xmlModule.py.

EnvConfig.xmlModule.XMLFile.xmlResult

Definition at line 16 of file xmlModule.py.

The documentation for this class was generated from the following file:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/cmake/EnvConfig/xmlModule.py