mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-12-23 14:32:18 +03:00
ahenk config parser
This commit is contained in:
parent
811f1f605a
commit
ae57488025
2 changed files with 51 additions and 0 deletions
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
|
||||
|
46
opt/ahenk/helper/ConfigurationHelper.py
Normal file
46
opt/ahenk/helper/ConfigurationHelper.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue