admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #/usr/bin/env python |
| 2 | ''' |
| 3 | Created on 07-Jan-2013 |
| 4 | |
| 5 | @author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com) |
| 6 | |
| 7 | TestON is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | TestON is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | |
| 21 | ''' |
| 22 | |
| 23 | import re |
| 24 | from configobj import ConfigObj |
| 25 | class iniparser: |
| 26 | ''' |
| 27 | Manages authoring, parsing and execution of the test. Sub components are |
| 28 | Test-Topology parser |
| 29 | Module that parses the test from plain English and topology |
| 30 | from a specification file and prepares for execution. |
| 31 | Test sequencer |
| 32 | Module that executes the tests case by case, |
| 33 | step by step adding ability for step by step pause and debug later. |
| 34 | Object loader |
| 35 | Module that connects and loads all the component connection objects |
| 36 | for access in the test |
| 37 | ''' |
| 38 | def __init__(self) : |
| 39 | self.default = '' |
| 40 | |
| 41 | def parse(self,fileName): |
| 42 | ''' |
| 43 | This will parse the params or topo or cfg file and return content in the file as Dictionary |
| 44 | ''' |
| 45 | self.fileName = fileName |
| 46 | matchFileName = re.match(r'(.*)\.(params|topo)',self.fileName,re.M|re.I) |
| 47 | if matchFileName: |
| 48 | try : |
| 49 | parsedInfo = ConfigObj(self.fileName) |
| 50 | return parsedInfo |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 51 | except Exception: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 52 | print "There is no such file to parse "+fileName |
| 53 | else: |
| 54 | return 0 |
| 55 | |
| 56 | def parseParams(self,paramsPath): |
| 57 | ''' |
| 58 | It will take the params file path and will return the params dictionary |
| 59 | ''' |
| 60 | |
| 61 | paramsPath = re.sub("\.","/",paramsPath) |
| 62 | paramsPath = re.sub("tests|examples","",paramsPath) |
| 63 | #print main.tests_path+"/"+paramsPath+".params" |
| 64 | params = self.parse(main.tests_path+paramsPath+".params") |
| 65 | paramsAsString = str(params) |
| 66 | return eval(paramsAsString) |
| 67 | |
| 68 | def parseTopology(self,topologyPath): |
| 69 | ''' |
| 70 | It will take topology file path and will return topology dictionary |
| 71 | ''' |
| 72 | topologyPath = re.sub("\.","/",topologyPath) |
| 73 | topologyPath = re.sub("tests|examples","",topologyPath) |
| 74 | topology = self.parse(main.tests_path+"/"+topologyPath+".topo") |
| 75 | topoAsString = str(topology) |
| 76 | return eval(topoAsString) |
| 77 | |