Package TestON :: Package core :: Module xmlparser
[hide private]
[frames] | no frames]

Source Code for Module TestON.core.xmlparser

 1  #/usr/bin/env python 
 2  ''' 
 3  Created on 07-Jan-2013 
 4          
 5  @author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com) 
 6  ''' 
 7   
 8  import xmldict 
 9  import re 
10   
11 -class xmlparser :
12
13 - def __init__(self) :
14 self.default = ''
15
16 - def parse(self,fileName) :
17 ''' 18 This will parse the params or topo or cfg file and return content in the file as Dictionary 19 ''' 20 self.fileName = fileName 21 matchFileName = re.match(r'(.*)\.(params|topo|cfg)', self.fileName, re.M | re.I) 22 if matchFileName: 23 xml = open(fileName).read() 24 try : 25 parsedInfo = xmldict.xml_to_dict(xml) 26 return parsedInfo 27 except : 28 print "There is no such file to parse " + fileName 29 else : 30 print "file name is not correct"
31
32 - def parseParams(self,paramsPath):
33 ''' 34 It will take the params file path and will return the params dictionary 35 ''' 36 paramsPath = re.sub("\.","/",paramsPath) 37 paramsPath = re.sub("tests|examples","",paramsPath) 38 params = self.parse(main.tests_path+paramsPath+".params") 39 paramsAsString = str(params) 40 return eval(paramsAsString)
41
42 - def parseTopology(self,topologyPath):
43 ''' 44 It will take topology file path and will return topology dictionary 45 ''' 46 topologyPath = re.sub("\.","/",topologyPath) 47 topologyPath = re.sub("tests|examples","",topologyPath) 48 topology = self.parse(main.tests_path+"/"+topologyPath+".topo") 49 topoAsString = str(topology) 50 return eval(topoAsString)
51