lars
794998f950
rendering bug of volume_properties fixed for ie fixed screen width in a mozilla/ie compatible way added german translation: 'log', 'network', 'volume_automount' and 'volume_details' fixed config management of 'plugin_manager' plugin fixed filtering of log level messages for 'logs' plugin updated documentation for ssl configurations changed default installation destinations in setup.py added nice background images to environment and help messages replaced message 'div' with 'fieldset' moved stylesheet data of plugins to html header (as required by spec) removed obsolete css definitions removed obsolete old perl/bash code improved 'update_po_files': remove obsolete msgids functionality of 'update_english.sh' moved to 'update_po_files' omit 'weblang' link attribute if it does not change the default setting changed default language from 'de' to 'en' fixed template bug that prevented the translation of plugin links fixed invalid html implement filecheck overriding for unittests
256 lines
7.1 KiB
Python
256 lines
7.1 KiB
Python
# $Id$
|
|
#
|
|
# parent class for all plugins of the CryptoBox
|
|
#
|
|
# 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
|
|
#
|
|
|
|
"""All features should inherit from this class.
|
|
"""
|
|
|
|
__revision__ = "$Id"
|
|
|
|
import os
|
|
import cherrypy
|
|
|
|
|
|
class CryptoBoxPlugin:
|
|
"""The base class of all features.
|
|
"""
|
|
|
|
## default capability is "system" - the other supported capability is: "volume"
|
|
plugin_capabilities = [ "system" ]
|
|
|
|
## where should the plugin be visible by default?
|
|
plugin_visibility = [ "preferences" ]
|
|
|
|
## does this plugin require admin authentification?
|
|
request_auth = False
|
|
|
|
## default rank (0..100) of the plugin in listings (lower value means higher priority)
|
|
rank = 80
|
|
|
|
|
|
## default icon of this plugin (relative path)
|
|
default_icon_filename = "plugin_icon.gif"
|
|
|
|
## fallback icon file (in the common plugin directory)
|
|
fallback_icon_filename = "plugin_icon_unknown.gif"
|
|
|
|
|
|
def __init__(self, cbox, plugin_dir, site_class=None):
|
|
self.cbox = cbox
|
|
self.hdf = {}
|
|
self.plugin_dir = plugin_dir
|
|
self.hdf_prefix = "Data.Plugins.%s." % self.get_name()
|
|
self.site = site_class
|
|
|
|
|
|
|
|
def do_action(self, **args):
|
|
"""Override do_action with your plugin code
|
|
"""
|
|
raise Exception, \
|
|
"undefined action handler ('do_action') in plugin '%s'" % self.get_name()
|
|
|
|
|
|
def get_status(self):
|
|
"""you should override this, to supply useful state information
|
|
"""
|
|
raise Exception, \
|
|
"undefined state handler ('get_status') in plugin '%s'" % self.get_name()
|
|
|
|
def is_useful(self, device):
|
|
"""Return if this plugin is useful for a specific device.
|
|
|
|
This should only be used for volume plugins. Nice for output filtering.
|
|
"""
|
|
return True
|
|
|
|
|
|
def get_name(self):
|
|
"""the name of the python file (module) should be the name of the plugin
|
|
"""
|
|
return self.__module__
|
|
|
|
|
|
def setup(self):
|
|
"""Any plugin that wants to define bootup actions may override this.
|
|
"""
|
|
pass
|
|
|
|
|
|
def cleanup(self):
|
|
"""Any plugin that wants to define shutdown actions may override this.
|
|
"""
|
|
pass
|
|
|
|
|
|
@cherrypy.expose
|
|
def get_icon(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 re
|
|
if (image is None) or (not re.match(r'[\w\-\.]*$', image)):
|
|
plugin_icon_file = os.path.join(self.plugin_dir, self.default_icon_filename)
|
|
else:
|
|
plugin_icon_file = os.path.join(self.plugin_dir, image)
|
|
if not os.access(plugin_icon_file, os.R_OK):
|
|
plugin_icon_file = os.path.join(
|
|
self.cbox.prefs["Locations"]["PluginDir"], self.fallback_icon_filename)
|
|
return cherrypy.lib.cptools.serveFile(plugin_icon_file)
|
|
|
|
|
|
def get_template_filename(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.plugin_dir, template_name + ".cs")
|
|
if os.access(result_file, os.R_OK) and os.path.isfile(result_file):
|
|
return result_file
|
|
else:
|
|
return None
|
|
|
|
|
|
def get_language_data(self):
|
|
"""Retrieve the language data of the feature.
|
|
|
|
Typically this is the content of the language.hdf file as a HDF object.
|
|
"""
|
|
import neo_cgi, neo_util
|
|
lang_hdf = neo_util.HDF()
|
|
lang_file = os.path.join(self.plugin_dir, 'language.hdf')
|
|
try:
|
|
lang_hdf.readFile(lang_file)
|
|
except (neo_util.Error, neo_util.ParseError):
|
|
self.cbox.log.error("failed to load language file (%s) of plugin (%s):" % \
|
|
(lang_file, self.get_name()))
|
|
return lang_hdf
|
|
|
|
|
|
def load_dataset(self, hdf):
|
|
"""Add the local values of the feature to the hdf dataset.
|
|
"""
|
|
for (key, value) in self.hdf.items():
|
|
hdf.setValue(key, str(value))
|
|
## add the stylesheet file if it exists
|
|
css_file = os.path.join(self.plugin_dir, self.get_name() + ".css")
|
|
if os.path.exists(css_file):
|
|
hdf.setValue("Data.StylesheetFiles.%s" % self.get_name(), css_file)
|
|
|
|
|
|
|
|
def is_auth_required(self):
|
|
"""check if this plugin requires authentication
|
|
first step: check plugin configuration
|
|
second step: check default value of plugin
|
|
"""
|
|
try:
|
|
if self.cbox.prefs.plugin_conf[self.get_name()]["requestAuth"] is None:
|
|
return self.request_auth
|
|
if self.cbox.prefs.plugin_conf[self.get_name()]["requestAuth"]:
|
|
return True
|
|
else:
|
|
return False
|
|
except KeyError:
|
|
return self.request_auth
|
|
|
|
|
|
def is_enabled(self):
|
|
"""check if this plugin is enabled
|
|
first step: check plugin configuration
|
|
second step: check default value of plugin
|
|
"""
|
|
fallback = bool(self.plugin_visibility)
|
|
try:
|
|
if self.cbox.prefs.plugin_conf[self.get_name()]["visibility"] is None:
|
|
return fallback
|
|
return bool(self.cbox.prefs.plugin_conf[self.get_name()]["visibility"])
|
|
except KeyError:
|
|
return fallback
|
|
|
|
|
|
def get_rank(self):
|
|
"""check the rank of this plugin
|
|
first step: check plugin configuration
|
|
second step: check default value of plugin
|
|
"""
|
|
try:
|
|
if self.cbox.prefs.plugin_conf[self.get_name()]["rank"] is None:
|
|
return int(self.rank)
|
|
return int(self.cbox.prefs.plugin_conf[self.get_name()]["rank"])
|
|
except (KeyError, TypeError):
|
|
return int(self.rank)
|
|
|
|
|
|
def set_rank(self, rank):
|
|
"""change the current rank of the plugin in plugin_conf
|
|
'rank' should be an integer
|
|
"""
|
|
pl_conf = self.cbox.prefs.plugin_conf
|
|
pl_name = self.get_name()
|
|
if pl_conf.has_key(pl_name):
|
|
pl_conf[pl_name]["rank"] = rank
|
|
else:
|
|
pl_conf[pl_name] = {}
|
|
pl_conf[pl_name]["rank"] = rank
|
|
|
|
|
|
def get_visibility(self):
|
|
"""Check which visibility flags of the feature are set.
|
|
"""
|
|
try:
|
|
if self.cbox.prefs.plugin_conf[self.get_name()]["visibility"] is None:
|
|
return self.plugin_visibility[:]
|
|
return self.cbox.prefs.plugin_conf[self.get_name()]["visibility"]
|
|
except KeyError:
|
|
return self.plugin_visibility
|
|
|
|
|
|
def reset(self):
|
|
"""Reinitialize the plugin.
|
|
|
|
This function should be called before every run
|
|
"""
|
|
self.hdf = {}
|
|
|
|
|
|
def get_test_class(self):
|
|
"""Return the unittest class of the feature.
|
|
"""
|
|
import imp
|
|
pl_file = os.path.join(self.plugin_dir, "unittests.py")
|
|
if os.access(pl_file, os.R_OK) and os.path.isfile(pl_file):
|
|
try:
|
|
return imp.load_source("unittests_%s" % self.get_name(), pl_file).unittests
|
|
except AttributeError:
|
|
pass
|
|
try:
|
|
self.cbox.log.info("could not load unittests for plugin: %s" % \
|
|
self.get_name())
|
|
except AttributeError:
|
|
pass
|
|
return None
|
|
|