@ -17,28 +17,6 @@ except ImportError:
class WebInterfacePlugins :
def __init__ ( self , log , plugins , handler_func ) :
for plugin in plugins . getPlugins ( ) :
if not plugin : continue
if not plugin . isEnabled ( ) : continue
plname = plugin . getName ( )
log . info ( " Plugin ' %s ' loaded " % plname )
## this should be the "easiest" way to expose all plugins as URLs
setattr ( self , plname , handler_func ( plugin ) )
setattr ( getattr ( self , plname ) , " exposed " , True )
# TODO: check, if this really works - for now the "stream_response" feature seems to be broken
#setattr(getattr(self, plname), "stream_respones", True)
class IconHandler :
def __init__ ( self , plugins ) :
self . plugins = PluginIconHandler ( plugins )
self . plugins . exposed = True
class PluginIconHandler :
def __init__ ( self , plugins ) :
@ -72,11 +50,31 @@ class WebInterfaceSites:
important : for _every_ " site " action ( cherrypy is stateful )
also take care for the plugins , as they also contain datasets
"""
self . pluginList = Plugins . PluginManager ( self . cbox , self . prefs [ " Locations " ] [ " PluginDir " ] )
self . plugins = WebInterfacePlugins ( self . log , self . pluginList , self . return_plugin_action )
self . __loadPlugins ( )
self . dataset = WebInterfaceDataset . WebInterfaceDataset ( self . cbox , self . prefs , self . pluginList . getPlugins ( ) )
## publish plugin icons
self . icons = IconHandler ( self . pluginList )
self . icons = PluginIconHandler ( self . pluginList )
self . icons . exposed = True
## check, if a configuration partition has become available
self . cbox . prefs . preparePartition ( )
def __loadPlugins ( self ) :
self . pluginList = Plugins . PluginManager ( self . cbox , self . prefs [ " Locations " ] [ " PluginDir " ] )
for plugin in self . pluginList . getPlugins ( ) :
if not plugin : continue
plname = plugin . getName ( )
if plugin . isEnabled ( ) :
self . cbox . log . info ( " Plugin ' %s ' loaded " % plname )
## this should be the "easiest" way to expose all plugins as URLs
setattr ( self , plname , self . return_plugin_action ( plugin ) )
setattr ( getattr ( self , plname ) , " exposed " , True )
# TODO: check, if this really works - for now the "stream_response" feature seems to be broken
#setattr(getattr(self, plname), "stream_respones", True)
else :
self . cbox . log . info ( " Plugin ' %s ' is disabled " % plname )
## remove the plugin, if it was active before
setattr ( self , plname , None )
## this is a function decorator to check authentication
@ -137,35 +135,58 @@ class WebInterfaceSites:
self . __resetDataset ( )
self . __checkEnvironment ( )
args_orig = dict ( args )
## set web interface language
try :
self . __setWebLang ( args [ " weblang " ] )
del args [ " weblang " ]
except KeyError :
self . __setWebLang ( " " )
## we always read the "device" setting - otherwise volume-plugin links
## would not work easily (see "volume_props" linking to "format_fs")
## it will get ignored for non-volume plugins
try :
plugin . device = None
if self . __setDevice ( args [ " device " ] ) :
plugin . device = args [ " device " ]
del args [ " device " ]
except KeyError :
pass
## check the device argument of volume plugins
if " volume " in plugin . pluginCapabilities :
try :
## initialize the dataset of the selected device if necessary
if self . __setDevice ( args [ " device " ] ) :
plugin . device = args [ " device " ]
self . dataset . setCurrentDiskState ( plugin . device )
else :
return self . __render ( self . defaultTemplate )
except KeyError :
return self . __render ( self . defaultTemplate )
## initialize the dataset of the selected device if necessary
if plugin . device :
self . dataset . setCurrentDiskState ( plugin . device )
else :
## the parameter 'device' exists - we have to remove it
del args [ " device " ]
## invalid (or missing) device setting
return self . __render ( self . defaultTemplate )
## check if there is a "redirect" setting - this will override the return
## value of the doAction function (e.g. useful for umount-before-format)
try :
if args [ " redirect " ] :
override_nextTemplate = { " plugin " : args [ " redirect " ] }
if " volume " in plugin . pluginCapabilities :
override_nextTemplate [ " values " ] = { " device " : plugin . device }
del args [ " redirect " ]
except KeyError :
override_nextTemplate = None
## call the plugin handler
nextTemplate = plugin . doAction ( * * args )
## for 'volume' plugins: reread the dataset of the current disk
## additionally: set the default template for plugins
if " volume " in plugin . pluginCapabilities :
## maybe the state of the current volume was changed?
self . dataset . setCurrentDiskState ( plugin . device )
if not nextTemplate : nextTemplate = { " plugin " : " volume_mount " , " values " : { " device " : plugin . device } }
else :
## maybe a non-volume plugin changed some plugin settings (e.g. plugin_manager)
self . dataset . setPluginData ( )
## update the container hdf-dataset (maybe a plugin changed the state of a container)
self . dataset . setContainersState ( )
## default page for non-volume plugins is the disk selection
if not nextTemplate : nextTemplate = { " plugin " : " disks " , " values " : { } }
## was a redirect requested?
if override_nextTemplate :
nextTemplate = override_nextTemplate
## if another plugins was choosen for 'nextTemplate', then do it!
if isinstance ( nextTemplate , types . DictType ) \
and " plugin " in nextTemplate . keys ( ) \
@ -216,7 +237,8 @@ class WebInterfaceSites:
examples are : non - https , readonly - config , . . .
"""
if not self . cbox . prefs . isWriteable ( ) :
## TODO: maybe add an option "mount"?
if self . cbox . prefs . requiresPartition ( ) and not self . cbox . prefs . getActivePartition ( ) :
self . dataset [ " Data.EnvironmentWarning " ] = " ReadOnlyConfig "
# TODO: turn this on soon (add "not") - for now it is annoying
if self . __checkHTTPS ( ) :
@ -298,7 +320,6 @@ class WebInterfaceSites:
def __setDevice ( self , device ) :
if device and re . match ( u ' [ \ w / \ -]+$ ' , device ) and self . cbox . getContainer ( device ) :
self . log . debug ( " select device: %s " % device )
self . dataset . setCurrentDiskState ( device )
return True
else :
self . log . warn ( " invalid device: %s " % device )
@ -383,9 +404,6 @@ class WebInterfaceSites:
yield " Couldn ' t read clearsilver file: %s " % cs_path
return
## update the container hdf-dataset (necessary if a plugin changed the state of a container)
self . dataset . setContainersState ( )
self . log . debug ( self . dataset )
for key in self . dataset . keys ( ) :
hdf . setValue ( key , str ( self . dataset [ key ] ) )