blob: 53fd471917f8a96f7d41be804fef96ed427bf107 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
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.Vemurifdb220a2016-10-19 14:09:53 -070017import sys
18
19class readProperties(object):
20 def __init__(self, strPropertiesFile):
21 self.strPropertiesFile = strPropertiesFile
22
23 @staticmethod
24 def parse_line(input):
Suchitra.Vemuri75dffd42016-12-20 15:35:25 -080025 key, value = input.split('=',1)
Suchitra.Vemurifdb220a2016-10-19 14:09:53 -070026 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.Vemurifdb220a2016-10-19 14:09:53 -070048 return value
Suchitra.Vemuri75dffd42016-12-20 15:35:25 -080049
50#test
51#test = readProperties("testProperties.py")
52#test.getValueProperties("CORE_INSTANCES")