From ae57488025de4278e8f3df4465d615ab53db6ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Mon, 1 Feb 2016 17:49:17 +0200 Subject: [PATCH] ahenk config parser --- opt/ahenk/ahenkd.py | 5 +++ opt/ahenk/helper/ConfigurationHelper.py | 46 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 opt/ahenk/helper/ConfigurationHelper.py diff --git a/opt/ahenk/ahenkd.py b/opt/ahenk/ahenkd.py index e69de29..bd72a3c 100644 --- a/opt/ahenk/ahenkd.py +++ b/opt/ahenk/ahenkd.py @@ -0,0 +1,5 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN + + diff --git a/opt/ahenk/helper/ConfigurationHelper.py b/opt/ahenk/helper/ConfigurationHelper.py new file mode 100644 index 0000000..bc2bf2f --- /dev/null +++ b/opt/ahenk/helper/ConfigurationHelper.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN + +import ConfigParser,os +from os import listdir +from os.path import isfile, join + +class ConfigurationHelper(object): + """ + This class written for configuration file management of ahenk and ahenk plugins + Sample ahenk configuration file path /etc/ahenk/ahenk.conf and sample ahenk plugins configuration folder path /etc/ahenk/config.d/ + Takes two argument, - both of them are optional - one of the is a configuration file path the other one is configuration files folder path + """ + def __init__(self, configurationFilePath=None, configurationFolderPath=None): + super(ConfigurationHelper, self).__init__() + self.configurationFilePath = configurationFilePath + self.configurationFolderPath = configurationFolderPath + + + def read(self): + configFiles = [] + + # Check if given ahenk configuration file exists + # If file exists add it to configFiles array. + if self.configurationFilePath: + if os.path.exists(self.configurationFilePath): + configFiles.append(self.configurationFilePath) + + if self.configurationFolderPath and os.path.exists(self.configurationFolderPath): + files = [f for f in listdir(self.configurationFolderPath) if isfile(join(self.configurationFolderPath, f))] + for f in files: + + configFiles.append(f) + + parser = SafeConfigParser() + configValues = parser.read(configFiles) + + return configValues + + + + + + +