cryptonas-branches/pythonrewrite/bin/CryptoBoxPlugin.py

66 lines
1.8 KiB
Python
Raw Normal View History

# $Id$
#
# parent class for all plugins of the CryptoBox
#
import os
class CryptoBoxPlugin:
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__
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"):
import neo_cgi, neo_util
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"))
for langFile in langFiles:
if os.access(langFile, os.R_OK):
lang_hdf = neo_util.HDF()
lang_hdf.readFile(langFile)
return lang_hdf
self.cbox.log.debug("Couldn't find a valid plugin language file (%s)" % str(langFiles))
return None
def loadDataSet(self, hdf):
for (key, value) in self.hdf.items():
hdf.setValue(key, str(value))