|
Gaudi Framework, version v23r4 |
| Home | Generated: Mon Sep 17 2012 |
Public Member Functions | |
| def | __init__ |
| def | variable |
| def | resetWriter |
| def | writeToFile |
| def | writeVar |
Public Attributes | |
| xmlResult | |
| declaredVars | |
| logger | |
| doc | |
Takes care of XML file operations such as reading and writing.
Definition at line 14 of file xmlModule.py.
| def EnvConfig::xmlModule::XMLFile::__init__ | ( | self ) |
Definition at line 17 of file xmlModule.py.
00018 : 00019 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' 00020 self.declaredVars = [] 00021 logConf = os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + '/log.conf') 00022 if not logging.getLogger('envLogger').handlers and os.path.exists(logConf): 00023 logging.config.fileConfig(logConf) 00024 self.logger = logging.getLogger('envLogger')
| def EnvConfig::xmlModule::XMLFile::resetWriter | ( | self ) |
resets the buffer of writer
Definition at line 79 of file xmlModule.py.
| def EnvConfig::xmlModule::XMLFile::variable | ( | self, | |
| path, | |||
namespace = 'EnvSchema', |
|||
name = None |
|||
| ) |
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 25 of file xmlModule.py.
00026 : 00027 '''Returns list containing name of variable, action and value 00028 00029 If no name given, returns list of lists of all variables and locals(instead of action 'local' is filled). 00030 ''' 00031 if not os.path.isfile(path): 00032 raise IOError('No such file.') 00033 sum = md5() 00034 sum.update(open(path, 'rb').read()) 00035 sum = sum.digest() 00036 00037 cpath = path + "c" # preparsed file 00038 try: 00039 f = open(cpath, 'rb') 00040 oldsum, data = load(f) 00041 if oldsum == sum: 00042 return data 00043 except: 00044 pass 00045 00046 # Get file 00047 self.doc = minidom.parse(path) 00048 if namespace == '': 00049 namespace = None 00050 00051 # Get all variables 00052 nodes = self.doc.getElementsByTagNameNS(namespace, "config")[0].childNodes 00053 variables = [] 00054 for node in nodes: 00055 # if it is an element node 00056 if node.nodeType == 1: 00057 varname = str(node.getAttribute('variable')) 00058 if name and varname != name: 00059 continue 00060 00061 action = str(node.localName) 00062 if action == 'declare': 00063 variables.append((action, (varname, str(node.getAttribute('type')), str(node.getAttribute('local'))))) 00064 else: 00065 if node.childNodes: 00066 value = str(node.childNodes[0].data) 00067 else: 00068 value = '' 00069 variables.append((action, (varname, value, None))) 00070 00071 try: 00072 f = open(cpath, 'wb') 00073 dump((sum, variables), f, protocol=2) 00074 f.close() 00075 except: 00076 pass 00077 return variables 00078
| def EnvConfig::xmlModule::XMLFile::writeToFile | ( | self, | |
outputFile = '' |
|||
| ) |
Finishes the XML input and writes XML to file.
Definition at line 84 of file xmlModule.py.
00085 : 00086 '''Finishes the XML input and writes XML to file.''' 00087 if(outputFile == ''): 00088 raise IOError("No output file given") 00089 self.xmlResult += '</env:config>' 00090 00091 doc = minidom.parseString(self.xmlResult) 00092 with open(outputFile, "w") as f: 00093 f.write( doc.toxml() ) 00094 00095 f.close() 00096 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 97 of file xmlModule.py.
00098 : 00099 '''Writes a action to a file. Declare undeclared elements (not local List is default type).''' 00100 if action == 'declare': 00101 self.xmlResult += '<env:declare variable="'+varName+'" type="'+ type.lower() +'" local="'+(str(local)).lower()+'" />\n' 00102 self.declaredVars.append(varName) 00103 return 00104 00105 if varName not in self.declaredVars: 00106 self.xmlResult += '<env:declare variable="'+varName+'" type="'+ type +'" local="'+(str(local)).lower()+'" />\n' 00107 self.declaredVars.append(varName) 00108 self.xmlResult += '<env:'+action+' variable="'+ varName +'">'+value+'</env:'+action+'>\n' 00109
Definition at line 17 of file xmlModule.py.
Definition at line 28 of file xmlModule.py.
Definition at line 17 of file xmlModule.py.
Definition at line 17 of file xmlModule.py.