2006-11-06 17:05:00 +01:00
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# parent class for all plugins of the CryptoBox
|
|
|
|
#
|
2006-11-30 15:50:28 +01:00
|
|
|
# Copyright 2006 sense.lab e.V.
|
|
|
|
#
|
|
|
|
# This file is part of the CryptoBox.
|
|
|
|
#
|
|
|
|
# The CryptoBox is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# The CryptoBox is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with the CryptoBox; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import cherrypy
|
|
|
|
|
|
|
|
|
|
|
|
class CryptoBoxPlugin:
|
|
|
|
|
|
|
|
## default capability is "system" - the other supported capability is: "volume"
|
|
|
|
pluginCapabilities = [ "system" ]
|
|
|
|
|
2006-11-08 13:20:30 +01:00
|
|
|
## where should the plugin be visible by default?
|
|
|
|
pluginVisibility = [ "preferences" ]
|
|
|
|
|
2006-11-06 17:05:00 +01:00
|
|
|
## does this plugin require admin authentification?
|
|
|
|
requestAuth = False
|
|
|
|
|
|
|
|
## default rank (0..100) of the plugin in listings (lower value means higher priority)
|
|
|
|
rank = 80
|
|
|
|
|
|
|
|
|
|
|
|
## default icon of this plugin (relative path)
|
2006-11-09 19:21:14 +01:00
|
|
|
defaultIconFileName = "plugin_icon.gif"
|
2006-11-06 17:05:00 +01:00
|
|
|
|
2006-11-15 12:47:37 +01:00
|
|
|
## fallback icon file (in the common plugin directory)
|
|
|
|
fallbackIconFileName = "plugin_icon_unknown.gif"
|
|
|
|
|
2006-11-06 17:05:00 +01:00
|
|
|
|
2006-11-29 15:02:33 +01:00
|
|
|
def __init__(self, cbox, pluginDir, siteClass=None):
|
2006-11-06 17:05:00 +01:00
|
|
|
self.cbox = cbox
|
|
|
|
self.hdf = {}
|
|
|
|
self.pluginDir = pluginDir
|
|
|
|
self.hdf_prefix = "Data.Plugins.%s." % self.getName()
|
2006-11-29 15:02:33 +01:00
|
|
|
self.site = siteClass
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
|
2006-11-08 13:20:30 +01:00
|
|
|
|
2006-11-06 17:05:00 +01:00
|
|
|
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__
|
|
|
|
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
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)
|
|
|
|
if not os.access(plugin_icon_file, os.R_OK):
|
2006-11-15 12:47:37 +01:00
|
|
|
plugin_icon_file = os.path.join(self.cbox.prefs["Locations"]["PluginDir"], self.fallbackIconFileName)
|
2006-11-06 17:05:00 +01:00
|
|
|
return cherrypy.lib.cptools.serveFile(plugin_icon_file)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2006-11-28 15:24:53 +01:00
|
|
|
def getLanguageData(self):
|
|
|
|
import neo_cgi, neo_util
|
2006-11-06 17:05:00 +01:00
|
|
|
lang_hdf = neo_util.HDF()
|
2006-11-28 15:24:53 +01:00
|
|
|
langFile = os.path.join(self.pluginDir, 'language.hdf')
|
|
|
|
try:
|
|
|
|
lang_hdf.readFile(langFile)
|
|
|
|
except (neo_util.Error, neo_util.ParseError), errMsg:
|
|
|
|
self.cbox.log.error("failed to load language file (%s) of plugin (%s):" % (langFile,self.getName()))
|
|
|
|
return lang_hdf
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
def loadDataSet(self, hdf):
|
|
|
|
for (key, value) in self.hdf.items():
|
|
|
|
hdf.setValue(key, str(value))
|
|
|
|
|
|
|
|
|
|
|
|
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"""
|
2006-11-08 13:20:30 +01:00
|
|
|
fallback = bool(self.pluginVisibility)
|
2006-11-06 17:05:00 +01:00
|
|
|
try:
|
2006-11-08 13:20:30 +01:00
|
|
|
if self.cbox.prefs.pluginConf[self.getName()]["visibility"] is None:
|
|
|
|
return fallback
|
|
|
|
return bool(self.cbox.prefs.pluginConf[self.getName()]["visibility"])
|
2006-11-06 17:05:00 +01:00
|
|
|
except KeyError:
|
2006-11-08 13:20:30 +01:00
|
|
|
return fallback
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
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"])
|
2006-11-22 16:21:21 +01:00
|
|
|
except (KeyError, TypeError):
|
2006-11-06 17:05:00 +01:00
|
|
|
return self.rank
|
2006-11-08 13:20:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
def getVisibility(self):
|
|
|
|
try:
|
|
|
|
if self.cbox.prefs.pluginConf[self.getName()]["visibility"] is None:
|
|
|
|
return self.pluginVisibility[:]
|
|
|
|
return self.cbox.prefs.pluginConf[self.getName()]["visibility"]
|
|
|
|
except KeyError:
|
|
|
|
return self.pluginVisibility
|
2006-11-06 17:05:00 +01: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
|
|
|
|
|