From a879f274073c23b62c756a8d4464e994c3476012 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 27 Feb 2019 12:41:29 +0100 Subject: [PATCH] remove old config class --- boswatch/config.py | 131 ------------------------------- boswatch/plugin/plugin.py | 7 +- boswatch/plugin/pluginManager.py | 6 +- config/server.ini | 60 -------------- config/server.yaml | 6 ++ plugins/template/template.ini | 4 - plugins/template/template.yaml | 4 + 7 files changed, 16 insertions(+), 202 deletions(-) delete mode 100644 boswatch/config.py delete mode 100644 config/server.ini delete mode 100644 plugins/template/template.ini create mode 100644 plugins/template/template.yaml diff --git a/boswatch/config.py b/boswatch/config.py deleted file mode 100644 index 16b2b00..0000000 --- a/boswatch/config.py +++ /dev/null @@ -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 diff --git a/boswatch/plugin/plugin.py b/boswatch/plugin/plugin.py index 73a4427..339c85a 100644 --- a/boswatch/plugin/plugin.py +++ b/boswatch/plugin/plugin.py @@ -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) diff --git a/boswatch/plugin/pluginManager.py b/boswatch/plugin/pluginManager.py index e1c541e..ac5b46e 100644 --- a/boswatch/plugin/pluginManager.py +++ b/boswatch/plugin/pluginManager.py @@ -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) diff --git a/config/server.ini b/config/server.ini deleted file mode 100644 index 9d4bce3..0000000 --- a/config/server.ini +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding: utf-8 -*- -# ____ ____ ______ __ __ __ _____ -# / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / -# / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < -# / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / -#/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ -# German BOS Information Script -# by Bastian Schroll - -[Server] -PORT = 8080 -Name = BW3 Server - -[FMS] -UseLists = -Allowed = -Denied = -RegEx = - -[POCSAG] -UseLists = -Allowed = -Denied = -Range = -RegEx = - -[ZVEI] -UseLists = -Allowed = -Denied = -Range = -RegEx = - -[Filter] -UseDoubleFilter = 0 -UseRegexFilter = 0 - -[doubleFilter] -# max number of entrys to save for comparison -MaxEntry = 30 -# time to ignore same alarm in seconds -IgnoreTime = 10 -# include pocsag msg in comparison -CheckMsg = 0 - -[regexFilter] - -[Description] -# load CSV description files with short and lon description -fms = 0 -pocsag = 0 -zvei = 0 - -[Plugins] -# here you can enable needed plugins -# 0 is disabled -# all greater than 0 enable the plugin -# the higher the number the earlier the plugin is called on alarm -# we call ist Plugin Prioority -template = 1 diff --git a/config/server.yaml b/config/server.yaml index d321a82..4a24d79 100644 --- a/config/server.yaml +++ b/config/server.yaml @@ -10,11 +10,16 @@ server: name: BW3 Server # name of the BW3 Server instance +plugins: + template: 1 + filter: doubleFilter: maxEntry: 30 ignoreTime: 10 checkMsg: no + + #[Server] #PORT = 8080 #Name = BW3 Server @@ -66,3 +71,4 @@ filter: ## the higher the number the earlier the plugin is called on alarm ## we call ist Plugin Prioority #template = 1 + diff --git a/plugins/template/template.ini b/plugins/template/template.ini deleted file mode 100644 index b51540a..0000000 --- a/plugins/template/template.ini +++ /dev/null @@ -1,4 +0,0 @@ -[Example] -String = Hello World! -bool = 1 -integer = 12 \ No newline at end of file diff --git a/plugins/template/template.yaml b/plugins/template/template.yaml new file mode 100644 index 0000000..4fde236 --- /dev/null +++ b/plugins/template/template.yaml @@ -0,0 +1,4 @@ +example: + string: Hello World! + bool: true + integer: 12