From 7e83d0876ddb84a45e130eeba28bc40ef53c074b Mon Sep 17 00:00:00 2001 From: Yaron Yogev Date: Thu, 27 Jul 2017 09:02:54 +0300 Subject: Calipso initial release for OPNFV Change-Id: I7210c244b0c10fa80bfa8c77cb86c9d6ddf8bc88 Signed-off-by: Yaron Yogev --- app/utils/config_file.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 app/utils/config_file.py (limited to 'app/utils/config_file.py') diff --git a/app/utils/config_file.py b/app/utils/config_file.py new file mode 100644 index 0000000..1982acc --- /dev/null +++ b/app/utils/config_file.py @@ -0,0 +1,48 @@ +############################################################################### +# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) # +# and others # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Apache License, Version 2.0 # +# which accompanies this distribution, and is available at # +# http://www.apache.org/licenses/LICENSE-2.0 # +############################################################################### +import os + + +class ConfigFile: + + def __init__(self, file_path): + super().__init__() + if not os.path.isfile(file_path): + raise ValueError("config file doesn't exist in " + "the system: {0}" + .format(file_path)) + self.config_file = file_path + + def read_config(self): + params = {} + try: + with open(self.config_file) as f: + for line in f: + line = line.strip() + if line.startswith("#") or " " not in line: + continue + index = line.index(" ") + key = line[: index].strip() + value = line[index + 1:].strip() + if value: + params[key] = value + except Exception as e: + raise e + return params + + @staticmethod + def get(file_name): + # config file is taken from app/config by default + # look in the current work directory to get the + # config path + python_path = os.environ['PYTHONPATH'] + if os.pathsep in python_path: + python_path = python_path.split(os.pathsep)[0] + return python_path + '/config/' + file_name -- cgit 1.2.3-korg