change pluginLoader and exception-handling

- if the function plugin.onLoad() throws an exception the plugin will skipped
- change exception-handling for pluginLoader
This commit is contained in:
JHCD 2015-06-29 23:24:48 +02:00
parent a1d610ee6a
commit 09b9cc5f7d
9 changed files with 100 additions and 72 deletions

View file

@ -29,20 +29,21 @@ def loadPlugins():
for i in getPlugins():
# call for each Plugin the loadPlugin() Methode
plugin = loadPlugin(i)
# Add it to globals.pluginList
globals.pluginList[i["name"]] = plugin
#call the .onLoad() routine for all active plugins
for pluginName, plugin in globals.pluginList.items():
logging.debug("call %s.onLoad()", pluginName)
# Try to call the .onLoad() routine for all active plugins
try:
plugin.onLoad(typ,freq,data)
logging.debug("call %s.onLoad()", i["name"])
plugin.onLoad()
# Add it to globals.pluginList
globals.pluginList[i["name"]] = plugin
except:
# call next plugin, if one has thrown an exception
logging.error("error calling %s.onLoad()", i["name"])
logging.debug("error calling %s.onLoad()", exc_info=True)
pass
except:
logging.exception("cannot load Plugins")
logging.error("cannot load Plugins")
logging.debug("cannot load Plugins", exc_info=True)
raise
def getPlugins():
@ -77,7 +78,9 @@ def getPlugins():
logging.warning("Plugin [NO CONF ] %s", i)
pass
except:
logging.exception("Error during Plugin search")
logging.error("Error during Plugin search")
logging.debug("cannot load Plugins", exc_info=True)
raise
return plugins
@ -97,4 +100,6 @@ def loadPlugin(plugin):
logging.debug("load Plugin: %s", plugin["name"])
return imp.load_module(plugin["name"], *plugin["info"])
except:
logging.exception("cannot load Plugin: %s", plugin["name"])
logging.error("cannot load Plugin: %s", plugin["name"])
logging.debug("cannot load Plugin: %s", plugin["name"], exc_info=True)
raise

View file

@ -21,24 +21,20 @@ from includes import globals # Global variables
##
#
# onLoad function of plugin
# will be called by the pluginLoader
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
#
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine are called
this onLoad() routine is called one time for initialize the plugin
@requires: nothing
@return: nothing
"""
try:
# we have to do nothing here...
pass
except:
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)
# nothing to do for this plugin
return
##
#

View file

@ -20,24 +20,21 @@ from includes import globals # Global variables
##
#
# onLoad function of plugin
# will be called by the pluginLoader
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
#
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine are called
this onLoad() routine is called one time for initialize the plugin
@requires: nothing
@return: nothing
"""
try:
# we have to do nothing here...
pass
except:
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)
# nothing to do for this plugin
return
##
#

View file

@ -21,25 +21,22 @@ from includes import globals # Global variables
##
#
# onLoad function of plugin
# will be called by the pluginLoader
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
#
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine are called
this onLoad() routine is called one time for initialize the plugin
@requires: nothing
@return: nothing
"""
try:
# we have to do nothing here...
pass
except:
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)
# nothing to do for this plugin
return
##
#
# Private helper function for a printable Timestamp
@ -47,6 +44,7 @@ def onLoad():
def curtime():
return time.strftime("%Y-%m-%d %H:%M:%S")
##
#
# do send mail

View file

@ -14,26 +14,23 @@ import socket
from includes import globals # Global variables
##
###
#
# onLoad function of plugin
# will be called by the pluginLoader
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
#
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine are called
this onLoad() routine is called one time for initialize the plugin
@requires: nothing
@return: nothing
"""
try:
# we have to do nothing here...
pass
except:
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)
# nothing to do for this plugin
return
##
#

View file

@ -17,24 +17,21 @@ from includes import globals # Global variables
##
#
# onLoad function of plugin
# will be called by the pluginLoader
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
#
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine are called
this onLoad() routine is called one time for initialize the plugin
@requires: nothing
@return: nothing
"""
try:
# we have to do nothing here...
pass
except:
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)
# nothing to do for this plugin
return
##
#

View file

@ -1,9 +1,9 @@
Handover to Plugin:
-------------------
typ = [FMS|ZVEI|POC]
freq = [Freq in Hz]
data = {"KEY1":"VALUE1","KEY2":"VALUE2"}
The following informations are included in the var "data".
They can be used by their Index Names: data['OPTION']
@ -29,6 +29,7 @@ POCSAG:
Global Objects:
---------------
1.)
import logging # Global logger
@ -38,4 +39,40 @@ Loglevel: debug|info|warning|error|exception|critical
2.)
import globals # Global variables
reads Data from the config.ini
VALUE = globals.config.get("SECTION", "OPTION")
VALUE = globals.config.get("SECTION", "OPTION")
General for plugins:
--------------------
All Plugins have to implement the following functions (see template.py):
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine is called one time for initialize the plugin
@requires: nothing
@return: nothing
@exception: Exception if init has an fatal error so that the plugin couldn't work
"""
def run(typ,freq,data):
"""
This function is the implementation of the Plugin.
If necessary the configuration hast to be set in the config.ini.
@type typ: string (FMS|ZVEI|POC)
@param typ: Typ of the dataset
@type data: map of data (structure see interface.txt)
@param data: Contains the parameter for dispatch
@type freq: string
@keyword freq: frequency of the SDR Stick
@requires: If necessary the configuration hast to be set in the config.ini.
@return: nothing
@exception: nothing, make sure this function will never thrown an exception
"""

View file

@ -18,24 +18,21 @@ from includes import globals # Global variables
##
#
# onLoad function of plugin
# will be called by the pluginLoader
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
#
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine are called
this onLoad() routine is called one time for initialize the plugin
@requires: nothing
@return: nothing
"""
try:
# we have to do nothing here...
pass
except:
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)
# nothing to do for this plugin
return
##
#

View file

@ -26,17 +26,19 @@ from includes import globals # Global variables
##
#
# onLoad function of plugin
# will be called by the pluginLoader
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
#
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine are called
this onLoad() routine is called one time for initialize the plugin
@requires: nothing
@return: nothing
@exception: Exception if init has an fatal error so that the plugin couldn't work
"""
try:
########## User onLoad CODE ##########
@ -45,6 +47,7 @@ def onLoad():
except:
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)
raise
##
#
@ -67,6 +70,7 @@ def run(typ,freq,data):
@requires: If necessary the configuration hast to be set in the config.ini.
@return: nothing
@exception: nothing, make sure this function will never thrown an exception
"""
try:
#