BOSWatch/plugin_test/pluginloader.py

35 lines
989 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 = []
possibleplugins = os.listdir(PluginFolder)
for i in possibleplugins:
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
logging.debug("found plugin: "+i)
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:
usePlugin = int(globals.config.get("Module", i))
except: #no entry for plugin found in config-file, skip
logging.warning("Plugin not in config: "+i)
logging.debug("use Plugin: "+str(usePlugin))
if usePlugin:
2015-05-19 15:43:15 +02:00
info = imp.find_module(i, [location])
2015-05-19 07:29:39 +02:00
plugins.append({"name": i, "info": info})
logging.debug("append Plugin: "+i)
return plugins
2015-05-18 09:04:16 +02:00
def loadPlugin(plugin):
2015-05-19 15:43:15 +02:00
return imp.load_module(plugin["name"], *plugin["info"])