2015-05-18 09:04:16 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: cp1252 -*-
|
|
|
|
|
|
2015-05-18 21:04:10 +02:00
|
|
|
import logging # Global logger
|
|
|
|
|
import globals # Global variables
|
2015-05-18 09:04:16 +02:00
|
|
|
import imp
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
PluginFolder = "./plugins"
|
|
|
|
|
MainModule = "__init__"
|
|
|
|
|
|
|
|
|
|
def getPlugins():
|
|
|
|
|
plugins = []
|
|
|
|
|
possibleplugins = os.listdir(PluginFolder)
|
|
|
|
|
for i in possibleplugins:
|
|
|
|
|
location = os.path.join(PluginFolder, i)
|
2015-05-18 21:04:10 +02:00
|
|
|
# plugins have to be a subdir with MainModule, if not skip
|
2015-05-18 09:04:16 +02:00
|
|
|
if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location):
|
|
|
|
|
continue
|
2015-05-18 21:04:10 +02:00
|
|
|
logging.debug("found plugin: "+i)
|
2015-05-18 21:49:03 +02:00
|
|
|
|
2015-05-18 21:04:10 +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
|
|
|
|
|
continue
|
|
|
|
|
logging.debug("use Plugin: "+str(usePlugin))
|
|
|
|
|
if usePlugin:
|
|
|
|
|
info = imp.find_module(MainModule, [location])
|
|
|
|
|
plugins.append({"name": i, "info": info})
|
|
|
|
|
logging.debug("append Plugin: "+i)
|
2015-05-18 09:04:16 +02:00
|
|
|
return plugins
|
|
|
|
|
|
|
|
|
|
def loadPlugin(plugin):
|
|
|
|
|
return imp.load_module(MainModule, *plugin["info"])
|