Changeset 79 for epics2xml/epics2xml.py
- Timestamp:
- Nov 6, 2009 10:35:02 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
epics2xml/epics2xml.py
r78 r79 27 27 from xml.dom import minidom 28 28 import datetime 29 import copy30 import pvConnect29 #import copy 30 #import pvConnect 31 31 32 32 … … 46 46 47 47 def GetConfigFile(self): 48 '''@return: name of XML settingsfile'''49 return self. settingsFile48 '''@return: name of XML configuration file''' 49 return self.configFile 50 50 51 51 def SetConfigFile(self, thefile): 52 52 '''set the name of XML configuration file 53 53 @param thefile: [string] name of XML file with the configuration''' 54 self. settingsFile = thefile54 self.configFile = thefile 55 55 56 56 def Clear(self): … … 58 58 self.db = {} 59 59 60 def ReadConfigFile(self): 61 '''read the configuration from a file into an internal dictionary (self.db) 62 63 @note: this method uses xml.dom.minidom (built into all Pythons) 64 @see: http://docs.python.org/library/xml.dom.minidom.html 65 ''' 66 try: 67 doc = minidom.parse(self.configFile) # parse an XML file by name 68 assert doc.documentElement.tagName == self.rootElement 69 except IOError: 70 return 'Could not read the XML file: ' + self.configFile 71 except AssertionError: 72 return 'XML root element is not ' + self.rootElement 73 #... read all attributes from the root element 74 docElem = doc.documentElement 75 self.Clear() 76 version = self._get_attribute(docElem, "version", "not-specified") 77 try: 78 # only handle v1.0 resource configuration files 79 assert version == u'1.0' 80 except AssertionError: 81 doc.unlink() 82 return 'Cannot handle file version:', version 83 # file verified now 84 60 85 def ReadXmlFile(self): 61 86 '''read the settings from a file into an internal dictionary (self.db) … … 65 90 ''' 66 91 try: 67 doc = minidom.parse(self. settingsFile) # parse an XML file by name92 doc = minidom.parse(self.configFile) # parse an XML file by name 68 93 assert doc.documentElement.tagName == self.rootElement 69 94 except IOError: 70 return 'Could not read the XML file: ' + self. settingsFile95 return 'Could not read the XML file: ' + self.configFile 71 96 except AssertionError: 72 97 return 'XML root element is not ' + self.rootElement … … 134 159 @see: http://www.boddie.org.uk/python/XML_intro.html 135 160 ''' 136 out = open(self. settingsFile, 'w')161 out = open(self.configFile, 'w') 137 162 out.write(repr(self)) 138 163 out.close() … … 141 166 # 142 167 143 return 'Saved settings to ' + self. settingsFile168 return 'Saved settings to ' + self.configFile 144 169 145 170 def _SetAttr(self, node, attribute, value): … … 227 252 228 253 if __name__ == '__main__': 254 cf = Epics2Xml("config.xml") 255 cf.ReadConfigFile() 229 256 # rc = Settings("examples/test-settings.xml") 230 257 # rc.ReadXmlFile()
Note: See TracChangeset
for help on using the changeset viewer.