mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2026-04-21 06:03:50 +00:00
remove old config class
This commit is contained in:
parent
e2ca436e5d
commit
a879f27407
7 changed files with 16 additions and 202 deletions
|
|
@ -1,131 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""!
|
||||
____ ____ ______ __ __ __ _____
|
||||
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
||||
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
||||
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
||||
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
||||
German BOS Information Script
|
||||
by Bastian Schroll
|
||||
|
||||
@file: config.py
|
||||
@date: 25.12.2017
|
||||
@author: Bastian Schroll
|
||||
@description: Module for the configuration
|
||||
"""
|
||||
import logging
|
||||
import configparser
|
||||
|
||||
logging.debug("- %s loaded", __name__)
|
||||
|
||||
|
||||
class Config:
|
||||
|
||||
_sharePoints = {}
|
||||
|
||||
def __init__(self):
|
||||
"""!Create a new config object and load the ini file directly"""
|
||||
self._config = configparser.ConfigParser()
|
||||
|
||||
def loadConfigFile(self, configPath, sharePoint=""):
|
||||
"""!loads a given configuration in the class wide config variable
|
||||
|
||||
@param configPath: Path to the config file
|
||||
@param sharePoint: If you want to share the config set name here
|
||||
@return True or False"""
|
||||
logging.debug("load config file from: %s", configPath)
|
||||
try:
|
||||
self._config.read(configPath, "utf-8")
|
||||
if sharePoint:
|
||||
self._shareConfig(sharePoint)
|
||||
return True
|
||||
except: # pragma: no cover
|
||||
logging.exception("cannot load config file")
|
||||
return False
|
||||
|
||||
def _shareConfig(self, sharePoint):
|
||||
"""!Shares the configuration
|
||||
|
||||
Shares the local _config to the class wide global _sharedConfig
|
||||
@param sharePoint: Name of the global share point
|
||||
@return True or False"""
|
||||
if sharePoint in self._sharePoints:
|
||||
logging.error("cannot share config - name is always in use: %s", sharePoint)
|
||||
return False
|
||||
else:
|
||||
self._sharePoints[sharePoint] = self._config
|
||||
logging.debug("add config sharePoint: %s", sharePoint)
|
||||
return True
|
||||
|
||||
def getInt(self, section, key, sharePoint=""):
|
||||
"""!Method to read a single config entry as integer
|
||||
|
||||
@param section: Section to read from
|
||||
@param key: Value to read
|
||||
@param sharePoint: Name of the global config share (empty is only local)
|
||||
@return An Integer or None"""
|
||||
value = self._get(section, key, sharePoint)
|
||||
if value is None:
|
||||
return None
|
||||
return int(value)
|
||||
|
||||
def getBool(self, section, key, sharePoint=""):
|
||||
"""!Method to read a single config entry as boolean
|
||||
|
||||
@param section: Section to read from
|
||||
@param key: Value to read
|
||||
@param sharePoint: Name of the global config share (empty is only local)
|
||||
@return True or False"""
|
||||
if self._get(section, key, sharePoint).lower() in ["1", "true", "yes"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def getStr(self, section, key, sharePoint=""):
|
||||
"""!Method to read a single config entry as string
|
||||
|
||||
@param section: Section to read from
|
||||
@param key: Value to read
|
||||
@param sharePoint: Name of the global config share (empty is only local)
|
||||
@return The value or None"""
|
||||
value = self._get(section, key, sharePoint)
|
||||
if value is None:
|
||||
return None
|
||||
return str(value)
|
||||
|
||||
def _get(self, section, key, sharePoint=""):
|
||||
"""!Method to read a single config entry
|
||||
|
||||
@param section: Section to read from
|
||||
@param key: Value to read
|
||||
@param sharePoint: Name of the global config share (empty is only local)
|
||||
@return The value or None"""
|
||||
if sharePoint:
|
||||
try:
|
||||
return self._sharePoints[sharePoint].get(section, key)
|
||||
except KeyError:
|
||||
logging.error("no sharePoint named: %s", sharePoint)
|
||||
except configparser.NoSectionError:
|
||||
logging.warning("no shared config section: %s", section)
|
||||
except configparser.NoOptionError:
|
||||
logging.warning("no shared config option: %s", key)
|
||||
except: # pragma: no cover
|
||||
logging.exception("error while reading shared config")
|
||||
return None
|
||||
|
||||
else:
|
||||
try:
|
||||
return self._config.get(section, key)
|
||||
except configparser.NoSectionError:
|
||||
logging.warning("no local config section: %s", section)
|
||||
except configparser.NoOptionError:
|
||||
logging.warning("no local config option: %s", key)
|
||||
except: # pragma: no cover
|
||||
logging.exception("error while reading local config")
|
||||
return None
|
||||
|
||||
def getAllSharepoints(self):
|
||||
"""!Return a python dict of all set sharepoints
|
||||
|
||||
@return Sharepoint dict"""
|
||||
return self._sharePoints
|
||||
|
|
@ -18,7 +18,7 @@ import logging
|
|||
import time
|
||||
|
||||
from boswatch.utils import paths
|
||||
from boswatch.config import Config
|
||||
from boswatch import configYaml
|
||||
from boswatch.utils import wildcard
|
||||
|
||||
logging.debug("- %s loaded", __name__)
|
||||
|
|
@ -52,9 +52,8 @@ class Plugin:
|
|||
self._alarmErrorCount = 0
|
||||
self._teardownErrorCount = 0
|
||||
|
||||
if paths.fileExist(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".ini"):
|
||||
self.config = Config()
|
||||
self.config.loadConfigFile(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".ini")
|
||||
if paths.fileExist(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".yaml"):
|
||||
self.config = configYaml.loadConfigFile(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".yaml")
|
||||
else:
|
||||
logging.debug("no config for %s found", pluginName)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import os
|
|||
import time
|
||||
import importlib
|
||||
|
||||
from boswatch.config import Config
|
||||
from boswatch import configYaml
|
||||
from boswatch.utils import paths
|
||||
|
||||
logging.debug("- %s loaded", __name__)
|
||||
|
|
@ -33,7 +33,7 @@ class PluginManager:
|
|||
|
||||
def __init__(self):
|
||||
"""!init comment"""
|
||||
self._config = Config()
|
||||
self._config = configYaml.loadConfigSharepoint("serverConfig")
|
||||
self._pluginList = []
|
||||
|
||||
def searchPluginDir(self):
|
||||
|
|
@ -45,7 +45,7 @@ class PluginManager:
|
|||
if not os.path.isdir(location) or not name + ".py" in os.listdir(location):
|
||||
continue
|
||||
|
||||
pluginPriority = self._config.getInt("Plugins", name, "serverConfig")
|
||||
pluginPriority = self._config["plugins"][name]
|
||||
|
||||
if pluginPriority is None:
|
||||
logging.warning("no entry in server config for plugin: %s", name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue