insert a Lots of Docu in includes

This commit is contained in:
Schrolli 2015-05-27 07:48:24 +02:00
parent c22400420a
commit 5394bceedf
9 changed files with 255 additions and 30 deletions

View file

@ -1,6 +1,14 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
"""
Functions to Load and import the Plugins
@author: Bastian Schroll
@requires: Configuration has to be set in the config.ini
"""
import logging # Global logger
import imp
import os
@ -8,23 +16,40 @@ import os
from includes import globals # Global variables
def loadPlugins():
"""
Load all Plugins into globals.pluginList
@return: nothing
@exception: Exception if insert into globals.pluginList failed
"""
try:
logging.debug("loading plugins")
#go to all Plugins from getPlugins()
for i in getPlugins():
#call for each Plugin the loadPlugin() Methode
plugin = loadPlugin(i)
#Add it to globals.pluginList
globals.pluginList[i["name"]] = plugin
except:
logging.exception("cannot load Plugins")
def getPlugins():
"""
get a Python Dict of all activeated Plugins
@return: Plugins as Python Dict
@exception: Exception if Plugin search failed
"""
try:
logging.debug("Search in Plugin Folder")
PluginFolder = globals.script_path+"/plugins"
plugins = []
#Go to all Folders in the Plugin-Dir
for i in os.listdir(PluginFolder):
location = os.path.join(PluginFolder, i)
#Skip if Path.isdir() or no File DIR_NAME.py is found
if not os.path.isdir(location) or not i + ".py" in os.listdir(location):
continue
@ -45,6 +70,16 @@ def getPlugins():
def loadPlugin(plugin):
"""
Imports a single Plugin
@type plugin: Plugin Data
@param plugin: Contains the information to import a Plugin
@return: nothing
@exception: Exception if Plugin import failed
"""
try:
logging.debug("load Plugin: %s", plugin["name"])
return imp.load_module(plugin["name"], *plugin["info"])