2006-09-25 14:22:41 +02:00
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# parent class for all plugins of the CryptoBox
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
2006-10-31 16:11:57 +01:00
|
|
|
import cherrypy
|
2006-09-25 14:22:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CryptoBoxPlugin:
|
|
|
|
|
2006-10-09 18:44:35 +02:00
|
|
|
## default capability is "system" - the other supported capability is: "volume"
|
|
|
|
pluginCapabilities = [ "system" ]
|
|
|
|
|
|
|
|
## does this plugin require admin authentification?
|
|
|
|
requestAuth = False
|
|
|
|
|
2006-10-11 17:51:28 +02:00
|
|
|
## is this plugin enabled by default?
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
## default rank (0..100) of the plugin in listings (lower value means higher priority)
|
|
|
|
rank = 80
|
|
|
|
|
2006-10-31 03:50:29 +01:00
|
|
|
|
|
|
|
## default icon of this plugin (relative path)
|
2006-10-31 16:11:57 +01:00
|
|
|
defaultIconFileName = "plugin_icon.png"
|
2006-10-31 03:50:29 +01:00
|
|
|
|
|
|
|
|
2006-09-25 14:22:41 +02:00
|
|
|
def __init__(self, cbox, pluginDir):
|
|
|
|
self.cbox = cbox
|
|
|
|
self.hdf = {}
|
|
|
|
self.pluginDir = pluginDir
|
|
|
|
self.hdf_prefix = "Data.Plugins.%s." % self.getName()
|
|
|
|
|
|
|
|
|
|
|
|
def doAction(self, **args):
|
|
|
|
"""override doAction with your plugin code"""
|
|
|
|
raise Exception, "undefined action handler ('doAction') in plugin '%'" % self.getName()
|
|
|
|
|
|
|
|
|
|
|
|
def getStatus(self):
|
|
|
|
"""you should override this, to supply useful state information"""
|
|
|
|
raise Exception, "undefined state handler ('getStatus') in plugin '%'" % self.getName()
|
|
|
|
|
|
|
|
|
|
|
|
def getName(self):
|
|
|
|
"""the name of the python file (module) should be the name of the plugin"""
|
|
|
|
return self.__module__
|
2006-10-31 03:50:29 +01:00
|
|
|
|
|
|
|
|
2006-10-31 16:11:57 +01:00
|
|
|
@cherrypy.expose
|
2006-11-01 10:20:29 +01:00
|
|
|
def getIcon(self, image=None, **kargs):
|
|
|
|
"""return the image data of the icon of the plugin
|
|
|
|
|
|
|
|
the parameter 'image' may be used for alternative image locations (relative
|
|
|
|
to the directory of the plugin)
|
|
|
|
'**kargs' is necessary, as a 'weblang' attribute may be specified (and ignored)"""
|
|
|
|
import cherrypy, re
|
|
|
|
if (image is None): # or (re.search(u'[\w-\.]', image)):
|
|
|
|
plugin_icon_file = os.path.join(self.pluginDir, self.defaultIconFileName)
|
|
|
|
else:
|
|
|
|
plugin_icon_file = os.path.join(self.pluginDir, image)
|
2006-10-31 16:11:57 +01:00
|
|
|
if not os.access(plugin_icon_file, os.R_OK):
|
|
|
|
plugin_icon_file = os.path.join(self.cbox.prefs["Locations"]["PluginDir"], "plugin_icon_unknown.png")
|
|
|
|
return cherrypy.lib.cptools.serveFile(plugin_icon_file)
|
2006-09-25 14:22:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
def getTemplateFileName(self, template_name):
|
|
|
|
"""return the filename of the template, if it is part of this plugin
|
|
|
|
|
|
|
|
use this function to check, if the plugin provides the specified template
|
|
|
|
"""
|
|
|
|
result_file = os.path.join(self.pluginDir, template_name + ".cs")
|
|
|
|
if os.access(result_file, os.R_OK) and os.path.isfile(result_file):
|
|
|
|
return result_file
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def getLanguageData(self, lang="en"):
|
2006-10-31 16:07:13 +01:00
|
|
|
try:
|
|
|
|
import neo_cgi, neo_util
|
|
|
|
except:
|
|
|
|
raise CryptoBoxExceptions.CBEnvironmentError("couldn't import 'neo_*'! Try 'apt-get install python-clearsilver'.")
|
2006-09-25 14:22:41 +02:00
|
|
|
langdir = os.path.abspath(os.path.join(self.pluginDir, "lang"))
|
|
|
|
## first: the default language file (english)
|
|
|
|
langFiles = [os.path.join(langdir, "en.hdf")]
|
|
|
|
## maybe we have to load a translation afterwards
|
|
|
|
if lang != "en":
|
|
|
|
langFiles.append(os.path.join(langdir, lang + ".hdf"))
|
2006-11-02 14:55:31 +01:00
|
|
|
file_found = False
|
|
|
|
lang_hdf = neo_util.HDF()
|
2006-09-25 14:22:41 +02:00
|
|
|
for langFile in langFiles:
|
|
|
|
if os.access(langFile, os.R_OK):
|
|
|
|
lang_hdf.readFile(langFile)
|
2006-11-02 14:55:31 +01:00
|
|
|
file_found = True
|
|
|
|
if file_found:
|
|
|
|
return lang_hdf
|
|
|
|
else:
|
|
|
|
self.cbox.log.debug("Couldn't find a valid plugin language file (%s)" % str(langFiles))
|
|
|
|
return None
|
2006-09-25 14:22:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
def loadDataSet(self, hdf):
|
|
|
|
for (key, value) in self.hdf.items():
|
|
|
|
hdf.setValue(key, str(value))
|
|
|
|
|
2006-10-11 17:51:28 +02:00
|
|
|
|
|
|
|
def isAuthRequired(self):
|
|
|
|
"""check if this plugin requires authentication
|
|
|
|
first step: check plugin configuration
|
|
|
|
second step: check default value of plugin"""
|
|
|
|
try:
|
|
|
|
if self.cbox.prefs.pluginConf[self.getName()]["requestAuth"] is None:
|
|
|
|
return self.requestAuth
|
|
|
|
if self.cbox.prefs.pluginConf[self.getName()]["requestAuth"]:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
except KeyError:
|
|
|
|
return self.requestAuth
|
|
|
|
|
|
|
|
|
|
|
|
def isEnabled(self):
|
|
|
|
"""check if this plugin is enabled
|
|
|
|
first step: check plugin configuration
|
|
|
|
second step: check default value of plugin"""
|
|
|
|
import types
|
|
|
|
try:
|
|
|
|
if self.cbox.prefs.pluginConf[self.getName()]["enabled"] is None:
|
|
|
|
return self.enabled
|
|
|
|
if self.cbox.prefs.pluginConf[self.getName()]["enabled"]:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
except KeyError:
|
|
|
|
return self.enabled
|
|
|
|
|
|
|
|
|
|
|
|
def getRank(self):
|
|
|
|
"""check the rank of this plugin
|
|
|
|
first step: check plugin configuration
|
|
|
|
second step: check default value of plugin"""
|
|
|
|
try:
|
|
|
|
if self.cbox.prefs.pluginConf[self.getName()]["rank"] is None:
|
|
|
|
return self.rank
|
|
|
|
return int(self.cbox.prefs.pluginConf[self.getName()]["rank"])
|
|
|
|
except KeyError, TypeError:
|
|
|
|
return self.rank
|
|
|
|
|
2006-10-26 14:28:50 +02:00
|
|
|
|
|
|
|
def getTestClass(self):
|
|
|
|
import imp
|
|
|
|
pl_file = os.path.join(self.pluginDir, "unittests.py")
|
|
|
|
if os.access(pl_file, os.R_OK) and os.path.isfile(pl_file):
|
|
|
|
try:
|
|
|
|
return getattr(imp.load_source("unittests_%s" % self.getName(), pl_file), "unittests")
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
self.cbox.log.info("could not load unittests for plugin: %s" % self.getName())
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
return None
|
|
|
|
|