From aa5698471fb9ff947c6064c70756b3c94dcb28e9 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sun, 14 Jan 2018 20:06:31 +0100 Subject: [PATCH] some little edits --- _info/functions.txt | 3 +-- boswatch/config.py | 8 ++++---- boswatch/plugin/plugin.py | 38 +++++++++++++++++++++++++++++------- config/server.ini | 2 +- plugins/template/template.py | 30 ++++++++++++++++++---------- 5 files changed, 57 insertions(+), 24 deletions(-) diff --git a/_info/functions.txt b/_info/functions.txt index afab147..ac02002 100644 --- a/_info/functions.txt +++ b/_info/functions.txt @@ -3,10 +3,9 @@ Dokumentation mittels Doxygen Unittests mittels pytest (zufällige Reihenfolge durch pytest-randomly) Codeabdeckung mittels pytest-cov PEP8 Design Kontrolle mittels pytest-pep8 -Logging mittels eigener Konfig-Datei einstellbar +Logging mittels eigener Config-Datei einstellbar Multi-Threading Server Komfortables Plugin System -Ausführliche Plugin Statistiken Beschreibung aus CSV File Konfigurationsdateien Modulweit teilbar über "Sharepoints" Alarm-Daten Übermittlung per definierten bwPacket-Paket diff --git a/boswatch/config.py b/boswatch/config.py index 3ed4cfb..2ce60f7 100644 --- a/boswatch/config.py +++ b/boswatch/config.py @@ -32,7 +32,7 @@ class Config: """!loads a given configuration in the class wide config variable @param configPath: Path to the config file - @param sharePoint: If you like to share the config + @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: @@ -47,7 +47,7 @@ class Config: def _shareConfig(self, sharePoint): """!Shares the configuration - Shares the local _config to teh class wide global _sharedConfig + Shares the local _config to the class wide global _sharedConfig @param sharePoint: Name of the global share point @return True or False""" try: @@ -65,10 +65,10 @@ class Config: @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 0""" + @return An Integer or None""" value = self._get(section, key, sharePoint) if value is None: - return 0 + return None return int(value) def getBool(self, section, key, sharePoint=""): diff --git a/boswatch/plugin/plugin.py b/boswatch/plugin/plugin.py index a3be01e..b5f230c 100644 --- a/boswatch/plugin/plugin.py +++ b/boswatch/plugin/plugin.py @@ -48,7 +48,9 @@ class Plugin: if paths.FileExist(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".ini"): self.config = Config() - self.config.loadConfigFile(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".ini", pluginName) + self.config.loadConfigFile(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".ini") + else: + logging.debug("no config for %s found", pluginName) logging.debug("[%s] onLoad()", pluginName) self.onLoad() @@ -82,11 +84,19 @@ class Plugin: self._setupTime = time.time() - self._tmpTime self._tmpTime = time.time() try: - logging.debug("[%s] alarm()", self._pluginName) - self.alarm(bwPacket) + + if bwPacket.get("mode") is "fms": + logging.debug("[%s] fms()", self._pluginName) + self.fms(bwPacket) + if bwPacket.get("mode") is "pocsag": + logging.debug("[%s] pocsag()", self._pluginName) + self.pocsag(bwPacket) + if bwPacket.get("mode") is "zvei": + logging.debug("[%s] zvei()", self._pluginName) + self.zvei(bwPacket) except: self._alarmErrorCount += 1 - logging.exception("[%s] error in alarm()", self._pluginName) + logging.exception("[%s] alarm error", self._pluginName) self._alarmTime = time.time() - self._tmpTime self._tmpTime = time.time() @@ -125,12 +135,26 @@ class Plugin: Must be inherit""" pass - def alarm(self, bwPacket): - """!Called on alarm + def fms(self, bwPacket): + """!Called on FMS alarm Must be inherit @param bwPacket: bwPacket instance""" - pass + logging.warning("ZVEI not implemented in %s", self._pluginName) + + def pocsag(self, bwPacket): + """!Called on POCSAG alarm + Must be inherit + + @param bwPacket: bwPacket instance""" + logging.warning("POCSAG not implemented in %s", self._pluginName) + + def zvei(self, bwPacket): + """!Called on ZVEI alarm + Must be inherit + + @param bwPacket: bwPacket instance""" + logging.warning("ZVEI not implemented in %s", self._pluginName) def teardown(self): """!Called after alarm diff --git a/config/server.ini b/config/server.ini index 393bea9..ecb691e 100644 --- a/config/server.ini +++ b/config/server.ini @@ -57,4 +57,4 @@ zvei = 0 # 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 \ No newline at end of file +template = 1 diff --git a/plugins/template/template.py b/plugins/template/template.py index 6d1f450..7fdb9d0 100644 --- a/plugins/template/template.py +++ b/plugins/template/template.py @@ -21,6 +21,7 @@ logging.debug("- %s loaded", __name__) class BoswatchPlugin(Plugin): + """!Description of the Plugin""" def __init__(self): """!Do not change anything here except the PLUGIN NAME in the super() call""" # PLEASE SET YOU PLUGIN NAME HERE !!!! @@ -28,25 +29,34 @@ class BoswatchPlugin(Plugin): def onLoad(self): """!Called by import of the plugin""" - logging.debug("onLoad") + pass def setup(self): """!Called before alarm""" - logging.info(self.config.getStr("Example", "String")) + pass - def alarm(self, bwPacket): - """!Called on alarm + def fms(self, bwPacket): + """!Called on FMS alarm @param bwPacket: bwPacket instance""" - logging.info(bwPacket) - logging.info(self.config.getBool("Example", "bool")) + pass + + def pocsag(self, bwPacket): + """!Called on POCSAG alarm + + @param bwPacket: bwPacket instance""" + pass + + def zvei(self, bwPacket): + """!Called on ZVEI alarm + + @param bwPacket: bwPacket instance""" + pass def teardown(self): - """!Called after alarm - Must be inherit""" - logging.info(self.config.getInt("Example", "integer")) + """!Called after alarm""" + pass def onUnload(self): - logging.debug("onUnload") """!Called by destruction of the plugin""" pass