mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
remove old config class
This commit is contained in:
parent
e2ca436e5d
commit
a879f27407
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
[Example]
|
||||
String = Hello World!
|
||||
bool = 1
|
||||
integer = 12
|
||||
4
plugins/template/template.yaml
Normal file
4
plugins/template/template.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
example:
|
||||
string: Hello World!
|
||||
bool: true
|
||||
integer: 12
|
||||
Loading…
Reference in a new issue