some little edits

This commit is contained in:
Bastian Schroll 2018-01-14 20:06:31 +01:00
parent d80db0d6cc
commit aa5698471f
5 changed files with 57 additions and 24 deletions

View file

@ -3,10 +3,9 @@ Dokumentation mittels Doxygen
Unittests mittels pytest (zufällige Reihenfolge durch pytest-randomly) Unittests mittels pytest (zufällige Reihenfolge durch pytest-randomly)
Codeabdeckung mittels pytest-cov Codeabdeckung mittels pytest-cov
PEP8 Design Kontrolle mittels pytest-pep8 PEP8 Design Kontrolle mittels pytest-pep8
Logging mittels eigener Konfig-Datei einstellbar Logging mittels eigener Config-Datei einstellbar
Multi-Threading Server Multi-Threading Server
Komfortables Plugin System Komfortables Plugin System
Ausführliche Plugin Statistiken
Beschreibung aus CSV File Beschreibung aus CSV File
Konfigurationsdateien Modulweit teilbar über "Sharepoints" Konfigurationsdateien Modulweit teilbar über "Sharepoints"
Alarm-Daten Übermittlung per definierten bwPacket-Paket Alarm-Daten Übermittlung per definierten bwPacket-Paket

View file

@ -32,7 +32,7 @@ class Config:
"""!loads a given configuration in the class wide config variable """!loads a given configuration in the class wide config variable
@param configPath: Path to the config file @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""" @return True or False"""
logging.debug("load config file from: %s", configPath) logging.debug("load config file from: %s", configPath)
try: try:
@ -47,7 +47,7 @@ class Config:
def _shareConfig(self, sharePoint): def _shareConfig(self, sharePoint):
"""!Shares the configuration """!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 @param sharePoint: Name of the global share point
@return True or False""" @return True or False"""
try: try:
@ -65,10 +65,10 @@ class Config:
@param section: Section to read from @param section: Section to read from
@param key: Value to read @param key: Value to read
@param sharePoint: Name of the global config share (empty is only local) @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) value = self._get(section, key, sharePoint)
if value is None: if value is None:
return 0 return None
return int(value) return int(value)
def getBool(self, section, key, sharePoint=""): def getBool(self, section, key, sharePoint=""):

View file

@ -48,7 +48,9 @@ class Plugin:
if paths.FileExist(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".ini"): if paths.FileExist(paths.PLUGIN_PATH + pluginName + "/" + pluginName + ".ini"):
self.config = Config() 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) logging.debug("[%s] onLoad()", pluginName)
self.onLoad() self.onLoad()
@ -82,11 +84,19 @@ class Plugin:
self._setupTime = time.time() - self._tmpTime self._setupTime = time.time() - self._tmpTime
self._tmpTime = time.time() self._tmpTime = time.time()
try: 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: except:
self._alarmErrorCount += 1 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._alarmTime = time.time() - self._tmpTime
self._tmpTime = time.time() self._tmpTime = time.time()
@ -125,12 +135,26 @@ class Plugin:
Must be inherit""" Must be inherit"""
pass pass
def alarm(self, bwPacket): def fms(self, bwPacket):
"""!Called on alarm """!Called on FMS alarm
Must be inherit Must be inherit
@param bwPacket: bwPacket instance""" @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): def teardown(self):
"""!Called after alarm """!Called after alarm

View file

@ -57,4 +57,4 @@ zvei = 0
# all greater than 0 enable the plugin # all greater than 0 enable the plugin
# the higher the number the earlier the plugin is called on alarm # the higher the number the earlier the plugin is called on alarm
# we call ist Plugin Prioority # we call ist Plugin Prioority
template = 1 template = 1

View file

@ -21,6 +21,7 @@ logging.debug("- %s loaded", __name__)
class BoswatchPlugin(Plugin): class BoswatchPlugin(Plugin):
"""!Description of the Plugin"""
def __init__(self): def __init__(self):
"""!Do not change anything here except the PLUGIN NAME in the super() call""" """!Do not change anything here except the PLUGIN NAME in the super() call"""
# PLEASE SET YOU PLUGIN NAME HERE !!!! # PLEASE SET YOU PLUGIN NAME HERE !!!!
@ -28,25 +29,34 @@ class BoswatchPlugin(Plugin):
def onLoad(self): def onLoad(self):
"""!Called by import of the plugin""" """!Called by import of the plugin"""
logging.debug("onLoad") pass
def setup(self): def setup(self):
"""!Called before alarm""" """!Called before alarm"""
logging.info(self.config.getStr("Example", "String")) pass
def alarm(self, bwPacket): def fms(self, bwPacket):
"""!Called on alarm """!Called on FMS alarm
@param bwPacket: bwPacket instance""" @param bwPacket: bwPacket instance"""
logging.info(bwPacket) pass
logging.info(self.config.getBool("Example", "bool"))
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): def teardown(self):
"""!Called after alarm """!Called after alarm"""
Must be inherit""" pass
logging.info(self.config.getInt("Example", "integer"))
def onUnload(self): def onUnload(self):
logging.debug("onUnload")
"""!Called by destruction of the plugin""" """!Called by destruction of the plugin"""
pass pass