From 60912ce7054363a188360ea8e41729ff3b107183 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 27 Feb 2019 08:39:54 +0100 Subject: [PATCH] first tests with yaml config --- boswatch/{config_yaml.py => configYaml.py} | 2 +- boswatch/filter/doubeFilter.py | 8 +-- boswatch/packet/packet.py | 14 ++--- bw_client.py | 8 +-- bw_server.py | 17 +----- config/client.ini | 49 ---------------- config/client.yaml | 17 +++--- config/server.yaml | 68 ++++++++++++++++++++++ 8 files changed, 94 insertions(+), 89 deletions(-) rename boswatch/{config_yaml.py => configYaml.py} (98%) delete mode 100644 config/client.ini create mode 100644 config/server.yaml diff --git a/boswatch/config_yaml.py b/boswatch/configYaml.py similarity index 98% rename from boswatch/config_yaml.py rename to boswatch/configYaml.py index be40fac..05dce6e 100644 --- a/boswatch/config_yaml.py +++ b/boswatch/configYaml.py @@ -9,7 +9,7 @@ German BOS Information Script by Bastian Schroll -@file: config_yaml.py +@file: configYaml.py @date: 27.02.2019 @author: Bastian Schroll @description: Module for the configuration in yaml format diff --git a/boswatch/filter/doubeFilter.py b/boswatch/filter/doubeFilter.py index c230155..68387e6 100644 --- a/boswatch/filter/doubeFilter.py +++ b/boswatch/filter/doubeFilter.py @@ -18,7 +18,7 @@ import logging import time -from boswatch.config import Config +from boswatch import configYaml logging.debug("- %s loaded", __name__) @@ -28,7 +28,7 @@ class DoubleFilter: def __init__(self): """!init""" - self._config = Config() + self._config = configYaml.loadConfigSharepoint("serverConfig")["filter"]["doubleFilter"] self._filterLists = {} def filter(self, bwPacket): @@ -57,14 +57,14 @@ class DoubleFilter: # delete entries that are to old counter = 0 for listPacket in self._filterLists[bwPacket.get("mode")][1:]: # [1:] skip first entry, thats the new one - if listPacket.get("timestamp") < (time.time() - self._config.getInt("doubleFilter", "IgnoreTime", "serverConfig")): + if listPacket.get("timestamp") < (time.time() - self._config["ignoreTime"]): self._filterLists[bwPacket.get("mode")].remove(listPacket) counter += 1 if counter: logging.debug("%d old entry(s) removed", counter) # delete last entry if list is to big - if len(self._filterLists[bwPacket.get("mode")]) > self._config.getInt("doubleFilter", "MaxEntry", "serverConfig"): + if len(self._filterLists[bwPacket.get("mode")]) > self._config["maxEntry"]: logging.debug("MaxEntry reached - delete oldest") self._filterLists[bwPacket.get("mode")].pop() diff --git a/boswatch/packet/packet.py b/boswatch/packet/packet.py index bf0103c..87510ec 100644 --- a/boswatch/packet/packet.py +++ b/boswatch/packet/packet.py @@ -16,7 +16,7 @@ """ import logging import time -from boswatch.config import Config +from boswatch import configYaml from boswatch import version logging.debug("- %s loaded", __name__) @@ -73,14 +73,14 @@ class Packet: - clientBranch - inputSource - frequency""" - config = Config() + config = configYaml.loadConfigSharepoint("clientConfig") logging.debug("add client data to bwPacket") - self.set("clientName", config.getStr("Client", "Name", "clientConfig")) + self.set("clientName", config["client"]["name"]) self.set("clientVersion", version.client) self.set("clientBuildDate", version.date) self.set("clientBranch", version.branch) - self.set("inputSource", config.getStr("Client", "InputSource", "clientConfig")) - self.set("frequency", config.getStr("Stick", "Frequency", "clientConfig")) + self.set("inputSource", config["client"]["inputSource"]) + self.set("frequency", config["inputSource"]["stick"]["frequency"]) def addServerData(self): """!Add the server information to the decoded data @@ -90,9 +90,9 @@ class Packet: - serverVersion - serverBuildDate - serverBranch""" - config = Config() + config = configYaml.loadConfigSharepoint("serverConfig") logging.debug("add server data to bwPacket") - self.set("serverName", config.getStr("Server", "Name", "serverConfig")) + self.set("serverName", config["server"]["name"]) self.set("serverVersion", version.server) self.set("serverBuildDate", version.date) self.set("serverBranch", version.branch) diff --git a/bw_client.py b/bw_client.py index 1ad813a..20b6c01 100644 --- a/bw_client.py +++ b/bw_client.py @@ -43,7 +43,7 @@ try: import time logging.debug("Import BOSWatch modules") - from boswatch import config_yaml + from boswatch import configYaml from boswatch.network.client import TCPClient from boswatch.decoder.decoder import Decoder from boswatch.utils import header @@ -69,14 +69,14 @@ try: parser.add_argument("-t", "--test", help="Client will send some testdata", action="store_true") # todo implement testmode args = parser.parse_args() - bwConfig = config_yaml.loadConfigFile(paths.CONFIG_PATH + args.config, "clientConfig") + bwConfig = configYaml.loadConfigFile(paths.CONFIG_PATH + args.config, "clientConfig") if bwConfig is None: logging.exception("cannot load config file") print("cannot load config file") - exit(1) # without config cannot _run + exit(1) # without config cannot run bwClient = TCPClient() - if bwClient.connect(bwConfig["servers"][0]["ip"], bwConfig["servers"][0]["port"]): + if bwClient.connect(bwConfig["server"]["ip"], bwConfig["server"]["port"]): while 1: for i in range(0, 5): diff --git a/bw_server.py b/bw_server.py index fcdab23..7c8982a 100644 --- a/bw_server.py +++ b/bw_server.py @@ -44,7 +44,7 @@ try: import queue logging.debug("Import BOSWatch modules") - from boswatch.config import Config + from boswatch import configYaml from boswatch.network.server import TCPServer from boswatch.packet.packet import Packet from boswatch.plugin.pluginManager import PluginManager @@ -96,8 +96,8 @@ try: parser.add_argument("-c", "--config", help="Name to configuration File", required=True) args = parser.parse_args() - bwConfig = Config() - if bwConfig.loadConfigFile(paths.CONFIG_PATH + args.config, "serverConfig") is False: + bwConfig = configYaml.loadConfigFile(paths.CONFIG_PATH + args.config, "serverConfig") + if bwConfig is None: logging.exception("cannot load config file") print("cannot load config file") exit(1) # without config cannot run @@ -107,14 +107,6 @@ try: bwPluginManager.importAllPlugins() bwPluginManager.loadAllPlugins() - bwDescriptor = Descriptor() - if bwConfig.getBool("Description", "fms"): - bwDescriptor.loadDescription("fms") - if bwConfig.getBool("Description", "pocsag"): - bwDescriptor.loadDescription("pocsag") - if bwConfig.getBool("Description", "zvei"): - bwDescriptor.loadDescription("zvei") - bwDoubleFilter = DoubleFilter() serverPaused = False # flag to pause alarming of server @@ -176,9 +168,6 @@ try: bwPacket.set("clientIP", data[0]) bwPacket.addServerData() - if bwConfig.getBool("Description", bwPacket.get("mode")): - bwDescriptor.addDescriptions(bwPacket) - bwPluginManager.runAllPlugins(bwPacket) # print(bwPacket.get("clientVersion")["major"]) incomingQueue.task_done() diff --git a/config/client.ini b/config/client.ini deleted file mode 100644 index 8a2acc9..0000000 --- a/config/client.ini +++ /dev/null @@ -1,49 +0,0 @@ -# -*- coding: utf-8 -*- -# ____ ____ ______ __ __ __ _____ -# / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / -# / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < -# / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / -#/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ -# German BOS Information Script -# by Bastian Schroll - -[Server] -# connection params to BOSWatch alarm server -IP = 127.0.0.1 -PORT = 8080 - -# you can set multiple servers (one line for each) -# the alarm data are served to all server simultane -# for each server you can set one backup server that be used if master is not reachable -# {indv. name} = {Master}:{PORT};{Slave}:{PORT} - -# Name Master Port|Slave Port -server1 = 127.0.0.1:8080 -serverTest = 127.0.0.1:1234;192.168.178.1:1234 - -[Client] -# information about this BOSWatch client instance -Name = BW3 Client - -# choose input source for multimon -# 'stick' or 'audio' -InputSource = stick - -[Stick] -# configuration for your DVB-T stick -Device = 0 -Frequency = 85.000M -PPMError = 0 -Squelch = 0 -Gain = 100 - -[Audio] -# configuration for audio input - -[Decoder] -# here you can enable needed decoders -FMS = 0 -ZVEI = 0 -POC512 = 0 -POC1200 = 0 -POC2400 = 0 diff --git a/config/client.yaml b/config/client.yaml index 022313b..a099a95 100644 --- a/config/client.yaml +++ b/config/client.yaml @@ -10,16 +10,13 @@ client: name: BW3 Client # name of the BW3 Client instance inputSource: stick # possible is 'stick' or 'audio' - useBroadcast: yes # use broadcast function to find server +# useBroadcast: yes # use broadcast function to find server -servers: # only used if useBroadcast = no - - name: Server one - ip: 127.0.0.1 - port: 8080 - - - name: Server two - ip: 11.12.13.14 - port: 5000 +# atm only one server possible +server: # only used if useBroadcast = no + name: Server one + ip: 127.0.0.1 + port: 8080 inputSource: stick: @@ -30,7 +27,7 @@ inputSource: Gain: 100 audio: # not implemented yet -decoder: +decoder: # not implemented yet fms: yes zvei: yes poc512: yes diff --git a/config/server.yaml b/config/server.yaml new file mode 100644 index 0000000..d321a82 --- /dev/null +++ b/config/server.yaml @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# ____ ____ ______ __ __ __ _____ +# / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / +# / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < +# / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +#/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ +# German BOS Information Script +# by Bastian Schroll + +server: + name: BW3 Server # name of the BW3 Server instance + +filter: + doubleFilter: + maxEntry: 30 + ignoreTime: 10 + checkMsg: no +#[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