blob: d7af564a734cbd3c102942ac5b9dc94b73515957 [file] [log] [blame]
# /usr/bin/env python
'''
Created on 07-Jan-2013
Copyright 2013 Open Networking Foundation (ONF)
Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
@author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
TestON is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TestON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TestON. If not, see <http://www.gnu.org/licenses/>.
'''
import xmldict
import re
import os.path
class xmlparser:
def __init__( self ):
self.default = ''
def parse( self, fileName ):
'''
This will parse the params or topo or cfg file and return content in the file as Dictionary
'''
self.fileName = fileName
matchFileName = re.match( r'(.*)\.(params|topo|cfg)', self.fileName, re.M | re.I )
if matchFileName:
xml = open( fileName ).read()
try:
parsedInfo = xmldict.xml_to_dict( xml )
return parsedInfo
except StandardError as e:
print "Error parsing file " + fileName + ": " + e.message
else:
print "File name is not correct"
def parseFile( self, fileName ):
'''
It will take a file path of an xml file and return the contents as a dictionary
'''
contents = self.parse( fileName )
return eval( str( contents ) )