BOSWatch/pluginloader.py

34 lines
960 B
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
PluginFolder = "./plugins"
2015-05-19 09:36:17 +02:00
2015-05-18 09:04:16 +02:00
def getPlugins():
2015-05-19 07:29:39 +02:00
plugins = []
2015-05-20 10:23:03 +02:00
for i in os.listdir(PluginFolder):
2015-05-19 07:29:39 +02:00
location = os.path.join(PluginFolder, i)
# plugins have to be a subdir with MainModule, if not skip
2015-05-19 15:43:15 +02:00
if not os.path.isdir(location) or not i + ".py" in os.listdir(location):
2015-05-19 07:29:39 +02:00
continue
2015-05-18 21:49:03 +02:00
2015-05-19 07:29:39 +02:00
# is the plugin enabled in the config-file?
try:
2015-05-20 10:23:03 +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)
2015-05-19 07:29:39 +02:00
except: #no entry for plugin found in config-file, skip
2015-05-20 10:23:03 +02:00
logging.warning("Plugin [NO CONF ] %s", i)
2015-05-19 07:29:39 +02:00
return plugins
2015-05-18 09:04:16 +02:00
def loadPlugin(plugin):
2015-05-19 22:24:42 +02:00
logging.debug("load Plugin: %s", plugin["name"])
2015-05-19 15:43:15 +02:00
return imp.load_module(plugin["name"], *plugin["info"])