BOSWatch/pluginloader.py

42 lines
1.2 KiB
Python
Raw Normal View History

2015-05-18 09:04:16 +02:00
#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging # Global logger
import globals # Global variables
2015-05-18 09:04:16 +02:00
import imp
import os
2015-05-19 09:36:17 +02:00
2015-05-18 09:04:16 +02:00
def getPlugins():
2015-05-22 09:51:59 +02:00
try:
logging.debug("Search in Plugin Folder")
PluginFolder = globals.script_path+"/plugins"
plugins = []
for i in os.listdir(PluginFolder):
location = os.path.join(PluginFolder, i)
# plugins have to be a subdir with MainModule, if not skip
if not os.path.isdir(location) or not i + ".py" in os.listdir(location):
continue
2015-05-18 21:49:03 +02:00
2015-05-22 09:51:59 +02:00
# is the plugin enabled in the config-file?
try:
2015-05-20 10:23:03 +02:00
logging.debug("Plugin [DISABLED] %s ", i)
2015-05-22 09:51:59 +02:00
if globals.config.getint("Plugins", i):
info = imp.find_module(i, [location])
plugins.append({"name": i, "info": info})
logging.debug("Plugin [ENABLED ] %s", i)
else:
logging.debug("Plugin [DISABLED] %s ", i)
except: #no entry for plugin found in config-file, skip
logging.warning("Plugin [NO CONF ] %s", i)
except:
logging.exception("Error during Plugin search")
2015-05-19 07:29:39 +02:00
return plugins
2015-05-18 09:04:16 +02:00
def loadPlugin(plugin):
2015-05-22 09:51:59 +02:00
try:
logging.debug("load Plugin: %s", plugin["name"])
return imp.load_module(plugin["name"], *plugin["info"])
except:
logging.exception("cannot load Plugin: %s", plugin["name"])