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)
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

View file

@ -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=""):

View file

@ -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

View file

@ -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