Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Suchitra.Vemuri | fdb220a | 2016-10-19 14:09:53 -0700 | [diff] [blame] | 17 | import sys |
| 18 | |
| 19 | class readProperties(object): |
| 20 | def __init__(self, strPropertiesFile): |
| 21 | self.strPropertiesFile = strPropertiesFile |
| 22 | |
| 23 | @staticmethod |
| 24 | def parse_line(input): |
Suchitra.Vemuri | 75dffd4 | 2016-12-20 15:35:25 -0800 | [diff] [blame] | 25 | key, value = input.split('=',1) |
Suchitra.Vemuri | fdb220a | 2016-10-19 14:09:53 -0700 | [diff] [blame] | 26 | key = key.strip() |
| 27 | value = value.strip() |
| 28 | return key, value |
| 29 | |
| 30 | @staticmethod |
| 31 | def getProperties(self): |
| 32 | data = {} |
| 33 | |
| 34 | with open(self.strPropertiesFile) as fp: |
| 35 | for line in fp: |
| 36 | line = line.strip() |
| 37 | if not line or line.startswith('#') or line.startswith('import'): |
| 38 | continue |
| 39 | |
| 40 | key, value = readProperties.parse_line(line) |
| 41 | data[key] = value |
| 42 | |
| 43 | return data |
| 44 | |
| 45 | def getValueProperties(self, key): |
| 46 | datas = readProperties.getProperties(self) |
| 47 | value = datas[key] |
Suchitra.Vemuri | fdb220a | 2016-10-19 14:09:53 -0700 | [diff] [blame] | 48 | return value |
Suchitra.Vemuri | 75dffd4 | 2016-12-20 15:35:25 -0800 | [diff] [blame] | 49 | |
| 50 | #test |
| 51 | #test = readProperties("testProperties.py") |
| 52 | #test.getValueProperties("CORE_INSTANCES") |