diff --git a/bin/CryptoBoxPlugin.py b/bin/CryptoBoxPlugin.py index abb3f0c..f84fddf 100644 --- a/bin/CryptoBoxPlugin.py +++ b/bin/CryptoBoxPlugin.py @@ -12,12 +12,12 @@ class CryptoBoxPlugin: ## default capability is "system" - the other supported capability is: "volume" pluginCapabilities = [ "system" ] + ## where should the plugin be visible by default? + pluginVisibility = [ "preferences" ] + ## does this plugin require admin authentification? requestAuth = False - ## is this plugin enabled by default? - enabled = True - ## default rank (0..100) of the plugin in listings (lower value means higher priority) rank = 80 @@ -33,6 +33,7 @@ class CryptoBoxPlugin: 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() @@ -125,16 +126,13 @@ class CryptoBoxPlugin: """check if this plugin is enabled first step: check plugin configuration second step: check default value of plugin""" - import types + fallback = bool(self.pluginVisibility) try: - if self.cbox.prefs.pluginConf[self.getName()]["enabled"] is None: - return self.enabled - if self.cbox.prefs.pluginConf[self.getName()]["enabled"]: - return True - else: - return False + if self.cbox.prefs.pluginConf[self.getName()]["visibility"] is None: + return fallback + return bool(self.cbox.prefs.pluginConf[self.getName()]["visibility"]) except KeyError: - return self.enabled + return fallback def getRank(self): @@ -147,6 +145,15 @@ class CryptoBoxPlugin: return int(self.cbox.prefs.pluginConf[self.getName()]["rank"]) except KeyError, TypeError: return self.rank + + + 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 def getTestClass(self): diff --git a/bin/CryptoBoxSettings.py b/bin/CryptoBoxSettings.py index 73ca9a6..8a59e9e 100644 --- a/bin/CryptoBoxSettings.py +++ b/bin/CryptoBoxSettings.py @@ -387,7 +387,7 @@ CryptoBoxRootActions = string(min=1) pluginValidationSpec = """ [__many__] -enabled = boolean(default=None) +visibility = boolean(default=None) requestAuth = boolean(default=None) rank = integer(default=None) """ diff --git a/bin/WebInterfaceDataset.py b/bin/WebInterfaceDataset.py index 7f2de6c..8f7fffa 100644 --- a/bin/WebInterfaceDataset.py +++ b/bin/WebInterfaceDataset.py @@ -101,15 +101,20 @@ class WebInterfaceDataset(dict): def setPluginData(self): for p in self.plugins: - lang_data = p.getLanguageData() entryName = "Settings.PluginList." + p.getName() + ## first: remove all existing settings of this plugin + for key in self.keys(): + if key.startswith(entryName): del self[key] + lang_data = p.getLanguageData() self[entryName] = p.getName() + self[entryName + ".Name"] = lang_data.getValue("Name", p.getName()) self[entryName + ".Link"] = lang_data.getValue("Link", p.getName()) self[entryName + ".Rank"] = p.getRank() self[entryName + ".RequestAuth"] = p.isAuthRequired() and "1" or "0" - self[entryName + ".Enabled"] = p.isEnabled() and "1" or "0" for a in p.pluginCapabilities: self[entryName + ".Types." + a] = "1" + for a in p.getVisibility(): + self[entryName + ".Visible." + a] = "1" def __setConfigValues(self): diff --git a/bin/WebInterfaceSites.py b/bin/WebInterfaceSites.py index 82405e9..e931bf3 100755 --- a/bin/WebInterfaceSites.py +++ b/bin/WebInterfaceSites.py @@ -169,6 +169,14 @@ class WebInterfaceSites: del args["redirect"] except KeyError: override_nextTemplate = None + ## check for information to be kept after the last call + try: + keep_values = args["message_keep"] + del args["message_keep"] + for key, value in keep_values["dataset"].items(): + self.dataset[key] = value + except KeyError: + keep_values = None ## call the plugin handler nextTemplate = plugin.doAction(**args) ## for 'volume' plugins: reread the dataset of the current disk @@ -195,8 +203,21 @@ class WebInterfaceSites: valueDict = dict(nextTemplate["values"]) ## force the current weblang attribute - otherwise it gets lost valueDict["weblang"] = self.dataset["Settings.Language"] + ## check for warnings/success messages, that should be kept + if "Data.Warning" in plugin.hdf.keys() \ + or "Data.Success" in plugin.hdf.keys(): + self.cbox.log.info("keep warning message") + valueDict["message_keep"] = { "plugin":plugin, "dataset":{}} + for keep_key in ("Data.Warning", "Data.Success"): + if keep_key in plugin.hdf.keys(): + valueDict["message_keep"]["dataset"][keep_key] = plugin.hdf[keep_key] new_plugin = self.pluginList.getPlugin(nextTemplate["plugin"]) return self.return_plugin_action(new_plugin)(**valueDict) + ## did we want to keep some dataset values? then save the specified plugin + if keep_values: + if type(nextTemplate) == types.StringType: + nextTemplate = { "template":nextTemplate } + nextTemplate["old_plugin"] = keep_values["plugin"] ## save the currently active plugin name self.dataset["Data.ActivePlugin"] = plugin.getName() return self.__render(nextTemplate, plugin) @@ -367,12 +388,16 @@ class WebInterfaceSites: ## is renderInfo a string (filename of the template) or a dictionary? if type(renderInfo) == types.DictType: template = renderInfo["template"] + if renderInfo.has_key("old_plugin"): + old_plugin = renderInfo["old_plugin"] + else: + old_plugin = None if renderInfo.has_key("generator"): generator = renderInfo["generator"] else: - generator = False + generator = None else: - (template, generator) = (renderInfo, None) + (template, generator, old_plugin) = (renderInfo, None, None) ## load the language data hdf = neo_util.HDF() @@ -392,7 +417,14 @@ class WebInterfaceSites: ## load the language data pl_lang = plugin.getLanguageData(self.dataset["Settings.Language"]) if pl_lang: + self.cbox.log.info("load plugin language: %s" % plugin.getName()) hdf.copy("Lang.Plugins.%s" % plugin.getName(), pl_lang) + ## was there an "old_plugin"? then load its language data, too + if old_plugin and (old_plugin != plugin): + pl_lang = old_plugin.getLanguageData(self.dataset["Settings.Language"]) + if pl_lang: + self.cbox.log.info("load old plugin language: %s" % old_plugin.getName()) + hdf.copy("Lang.Plugins.%s" % old_plugin.getName(), pl_lang) ## load the dataset of the plugin plugin.loadDataSet(hdf) @@ -411,7 +443,7 @@ class WebInterfaceSites: cs.parseFile(cs_path) ## is there a generator containing additional information? - if generator is None: + if not generator: ## all content in one flush yield cs.render() else: