allow alternative filename for "getIcon"

allow redirection from one plugin to another
removed obsolete sites (now handled by plugins)
This commit is contained in:
lars 2006-11-01 09:20:29 +00:00
parent 9cde0b943a
commit 7fd361d8ac
2 changed files with 29 additions and 86 deletions

View file

@ -49,10 +49,17 @@ class CryptoBoxPlugin:
@cherrypy.expose @cherrypy.expose
def getIcon(self): def getIcon(self, image=None, **kargs):
"""return the image data of the icon of the plugin""" """return the image data of the icon of the plugin
import cherrypy
plugin_icon_file = os.path.join(self.pluginDir, self.defaultIconFileName) 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): 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") plugin_icon_file = os.path.join(self.cbox.prefs["Locations"]["PluginDir"], "plugin_icon_unknown.png")
return cherrypy.lib.cptools.serveFile(plugin_icon_file) return cherrypy.lib.cptools.serveFile(plugin_icon_file)

View file

@ -4,6 +4,7 @@ import re
import Plugins import Plugins
from CryptoBoxExceptions import * from CryptoBoxExceptions import *
import cherrypy import cherrypy
import types
class WebInterfacePlugins: class WebInterfacePlugins:
@ -40,9 +41,11 @@ class PluginIconHandler:
class WebInterfaceSites: class WebInterfaceSites:
''' '''
url2func = {'index':'show_status','doc':'show_doc','logs':'show_log'}
''' '''
## this template is used under strange circumstances
defaultTemplate = "empty"
def __init__(self): def __init__(self):
import logging import logging
@ -60,23 +63,11 @@ class WebInterfaceSites:
""" """
self.pluginList = Plugins.PluginManager(self.cbox, self.prefs["Locations"]["PluginDir"]) self.pluginList = Plugins.PluginManager(self.cbox, self.prefs["Locations"]["PluginDir"])
self.plugins = WebInterfacePlugins(self.log, self.pluginList, self.return_plugin_action) self.plugins = WebInterfacePlugins(self.log, self.pluginList, self.return_plugin_action)
## publish the url "/system" as an alias for "/plugins"
self.plugins.index = self.system
self.dataset = WebInterfaceDataset.WebInterfaceDataset(self.cbox, self.prefs, self.pluginList.getPlugins()) self.dataset = WebInterfaceDataset.WebInterfaceDataset(self.cbox, self.prefs, self.pluginList.getPlugins())
## publish plugin icons ## publish plugin icons
self.icons = IconHandler(self.pluginList) self.icons = IconHandler(self.pluginList)
def __check_config(self):
#TODO: from now on a cryptobox is always configured
return True
def __check_init_running(self):
#TODO: implement this check (is mkfs still running?)
return False
## this is a function decorator to check authentication ## this is a function decorator to check authentication
## it has to be defined before any page definition requiring authentification ## it has to be defined before any page definition requiring authentification
def __requestAuth(self=None): def __requestAuth(self=None):
@ -119,75 +110,12 @@ class WebInterfaceSites:
## put real sites down here and don't forget to expose them at the end ## put real sites down here and don't forget to expose them at the end
@cherrypy.expose
def status(self, weblang=""):
'''shows the current status of the box
'''
self.__resetDataset()
self.__setWebLang(weblang)
if not self.__check_config():
self.dataset["Data.Warning"] = "NotInitialized"
return self.__render("form_init")
elif self.__check_init_running():
self.dataset["Data.Warning"] = "InitNotFinished"
self.dataset["Data.Redirect.Action"] = "form_config"
self.dataset["Data.Redirect.Delay"] = "30"
return self.__render("empty")
else:
self.dataset["Data.Redirect.Delay"] = "60"
return self.__render("show_status")
@cherrypy.expose
def doc(self,page="",weblang=""):
'''prints the offline wikipage
'''
import re
self.__resetDataset()
self.__setWebLang(weblang)
## check for invalid characters
if page and not re.search(u'\W', page):
self.dataset["Data.Doc.Page"] = page
else:
## display this page as default help page
self.dataset["Data.Doc.Page"] ="CryptoBoxUser"
return self.__render("show_doc")
@cherrypy.expose
def system(self, weblang=""):
self.__resetDataset()
self.__setWebLang(weblang)
return self.__render("form_system")
@cherrypy.expose @cherrypy.expose
def index(self, weblang=""): def index(self, weblang=""):
self.__resetDataset() self.__resetDataset()
self.__setWebLang(weblang) self.__setWebLang(weblang)
return self.__render("show_status") ## render "disks" plugin by default
return self.return_plugin_action(self.pluginList.getPlugin("disks"))()
@cherrypy.expose
def show_volume(self, device="", weblang=""):
self.__resetDataset()
self.__setWebLang(weblang)
if self.__setDevice(device):
return self.__render("show_volume")
else:
if self.cbox.getContainerList():
return self.__render("show_volumes")
else:
return self.__render("show_status")
@cherrypy.expose
def show_volumes(self, weblang=""):
self.__resetDataset()
self.__setWebLang(weblang)
return self.__render("show_volumes")
def return_plugin_action(self, plugin): def return_plugin_action(self, plugin):
@ -206,9 +134,9 @@ class WebInterfaceSites:
plugin.device = args["device"] plugin.device = args["device"]
self.dataset.setCurrentDiskState(plugin.device) self.dataset.setCurrentDiskState(plugin.device)
else: else:
return self.__render("show_status") return self.__render(self.defaultTemplate)
except KeyError: except KeyError:
return self.__render("show_status") return self.__render(self.defaultTemplate)
else: else:
## the parameter 'device' exists - we have to remove it ## the parameter 'device' exists - we have to remove it
del args["device"] del args["device"]
@ -218,10 +146,18 @@ class WebInterfaceSites:
## additionally: set the default template for plugins ## additionally: set the default template for plugins
if "volume" in plugin.pluginCapabilities: if "volume" in plugin.pluginCapabilities:
self.dataset.setCurrentDiskState(plugin.device) self.dataset.setCurrentDiskState(plugin.device)
if not nextTemplate: nextTemplate = "show_volume" if not nextTemplate: nextTemplate = { "plugin":"volume_mount", "values":{"device":plugin.device}}
else: else:
self.dataset.setPluginData() self.dataset.setPluginData()
if not nextTemplate: nextTemplate = "form_system" if not nextTemplate: nextTemplate = { "plugin":"disks", "values":{} }
## if another plugins was choosen for 'nextTemplate', then do it!
if isinstance(nextTemplate, types.DictType) \
and "plugin" in nextTemplate.keys() \
and "values" in nextTemplate.keys() \
and self.pluginList.getPlugin(nextTemplate["plugin"]):
valueDict = nextTemplate["values"]
new_plugin = self.pluginList.getPlugin(nextTemplate["plugin"])
return self.return_plugin_action(new_plugin)(**valueDict)
## save the currently active plugin name ## save the currently active plugin name
self.dataset["Data.ActivePlugin"] = plugin.getName() self.dataset["Data.ActivePlugin"] = plugin.getName()
return self.__render(nextTemplate, plugin) return self.__render(nextTemplate, plugin)