From 8316ce161482ba30183ea54493748d30c0f99947 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Fri, 22 May 2015 11:44:50 +0200 Subject: [PATCH] edit plugin_test.py --- plugin_test.py | 63 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/plugin_test.py b/plugin_test.py index 915aa7f..cda6ed4 100644 --- a/plugin_test.py +++ b/plugin_test.py @@ -1,15 +1,18 @@ #!/usr/bin/python # -*- coding: cp1252 -*- -import time +########################################################################### +# Use this as a simple Plugin Loading Tool to test your own Coded Plugins # +########################################################################### + +import globals # Global variables import pluginloader -import os #for absolute path: os.path.dirname(os.path.abspath(__file__)) - import logging -import globals import ConfigParser #for parse the config file +import os #for log mkdir +import time #timestamp for doublealarm #create new logger logger = logging.getLogger() @@ -34,37 +37,53 @@ logger.addHandler(ch) #exception - error with exception message in log #critical - critical error, program exit +globals.script_path = os.path.dirname(os.path.abspath(__file__)) -#ConfigParser -logging.debug("reading config file") try: + logging.debug("reading config file") globals.config = ConfigParser.ConfigParser() - globals.config.read(globals.script_path+"./config/config.ini") + globals.config.read(globals.script_path+"/config/config.ini") + for key,val in globals.config.items("Plugins"): + logging.debug(" - %s = %s", key, val) except: - logging.exception("cannot read config file") + logging.debug("cannot read config file") +try: + logging.debug("loading plugins") + pluginList = {} + for i in pluginloader.getPlugins(): + plugin = pluginloader.loadPlugin(i) + pluginList[i["name"]] = plugin + logging.debug("loading ready") +except: + logging.exception("cannot load Plugins") + + +# ----- Test Data ----- # +#typ = "FMS" +#data = {"fms":"12345678", "status":"2", "direction":"1", "tsi":"III"} + +typ = "ZVEI" data = {"zvei":"12345"} -#data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} - -logging.debug("Load Plugins...") - -pluginList = {} -for i in pluginloader.getPlugins(): - plugin = pluginloader.loadPlugin(i) - pluginList[i["name"]] = plugin - -logging.debug("All loaded...") +#typ = "POC" +#data = {"ric":"1234567", "function":"1", "msg":"Hello World!, "bitrate":"1200"} while True: try: time.sleep(1) - logging.info(" = = = = = = = = = ") - logging.info("Alarm!") + + print "" + logging.debug("[ ALARM ]") for name, plugin in pluginList.items(): logging.debug("call Plugin: %s", name) - plugin.run("ZVEI","0",data) + plugin.run(typ,"0",data) + logging.debug("[END ALARM]") + + except KeyboardInterrupt: + logging.warning("Keyboard Interrupt") + exit() except: - logging.exception("Cannot Throw Modules") + logging.exception("unknown error") exit() \ No newline at end of file