admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #/usr/bin/env python |
| 2 | ''' |
| 3 | Created on 07-Jan-2013 |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 4 | Modified 2015 by ON.Lab |
| 5 | |
| 6 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 7 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 8 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 9 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 10 | @author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com) |
| 11 | |
| 12 | TestON is free software: you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation, either version 2 of the License, or |
| 15 | (at your option) any later version. |
| 16 | |
| 17 | TestON is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 23 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 24 | |
| 25 | |
| 26 | ''' |
| 27 | |
| 28 | import xmldict |
| 29 | import re |
| 30 | |
| 31 | class xmlparser : |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 32 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 33 | def __init__(self) : |
| 34 | self.default = '' |
| 35 | |
| 36 | def parse(self,fileName) : |
| 37 | ''' |
| 38 | This will parse the params or topo or cfg file and return content in the file as Dictionary |
| 39 | ''' |
| 40 | self.fileName = fileName |
| 41 | matchFileName = re.match(r'(.*)\.(params|topo|cfg)', self.fileName, re.M | re.I) |
| 42 | if matchFileName: |
| 43 | xml = open(fileName).read() |
| 44 | try : |
| 45 | parsedInfo = xmldict.xml_to_dict(xml) |
| 46 | return parsedInfo |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 47 | except StandardError as e: |
Jon Hall | 0946f65 | 2015-08-13 11:44:38 -0700 | [diff] [blame] | 48 | print "Error parsing file " + fileName + ": " + e.message |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 49 | else : |
Jon Hall | 0946f65 | 2015-08-13 11:44:38 -0700 | [diff] [blame] | 50 | print "File name is not correct" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 51 | |
| 52 | def parseParams(self,paramsPath): |
| 53 | ''' |
| 54 | It will take the params file path and will return the params dictionary |
| 55 | ''' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 56 | paramsPath = re.sub("\.","/",paramsPath) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 57 | paramsPath = re.sub("tests|examples","",paramsPath) |
| 58 | params = self.parse(main.tests_path+paramsPath+".params") |
| 59 | paramsAsString = str(params) |
| 60 | return eval(paramsAsString) |
| 61 | |
| 62 | def parseTopology(self,topologyPath): |
| 63 | ''' |
| 64 | It will take topology file path and will return topology dictionary |
| 65 | ''' |
| 66 | topologyPath = re.sub("\.","/",topologyPath) |
| 67 | topologyPath = re.sub("tests|examples","",topologyPath) |
andrewonlab | 31d9f2d | 2014-10-09 13:25:13 -0400 | [diff] [blame] | 68 | #topology = self.parse(main.tests_path+"/"+topologyPath+".topo") |
| 69 | topology = self.parse(main.tests_path+topologyPath+".topo") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 70 | topoAsString = str(topology) |
| 71 | return eval(topoAsString) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 72 | |