diff options
Diffstat (limited to 'module/api/ConfigApi.py')
| -rw-r--r-- | module/api/ConfigApi.py | 77 | 
1 files changed, 49 insertions, 28 deletions
| diff --git a/module/api/ConfigApi.py b/module/api/ConfigApi.py index f3f2e6950..ffcdbabec 100644 --- a/module/api/ConfigApi.py +++ b/module/api/ConfigApi.py @@ -1,7 +1,7 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -from module.Api import Api, UserContext, RequirePerm, Permission, ConfigHolder, ConfigItem +from module.Api import Api, UserContext, RequirePerm, Permission, ConfigHolder, ConfigItem, PluginInfo  from module.utils import to_string  from ApiComponent import ApiComponent @@ -9,6 +9,7 @@ from ApiComponent import ApiComponent  class ConfigApi(ApiComponent):      """ Everything related to configuration """ +    @UserContext      def getConfigValue(self, section, option):          """Retrieve config value. @@ -17,9 +18,10 @@ class ConfigApi(ApiComponent):          :rtype: str          :return: config value as string          """ -        value = self.core.config.get(section, option) +        value = self.core.config.get(section, option, self.user)          return to_string(value) +    @UserContext      def setConfigValue(self, section, option, value):          """Set new config value. @@ -30,49 +32,69 @@ class ConfigApi(ApiComponent):          if option in ("limit_speed", "max_speed"): #not so nice to update the limit              self.core.requestFactory.updateBucket() -        self.core.config.set(section, option, value) +        self.core.config.set(section, option, value, self.user)      def getConfig(self):          """Retrieves complete config of core. -        :rtype: ConfigHolder -        :return: dict with section mapped to config +        :rtype: dict of section -> ConfigHolder          """ -        # TODO -        return dict([(section, ConfigHolder(section, data.name, data.description, data.long_desc, [ -        ConfigItem(option, d.name, d.description, d.type, to_string(d.default), -            to_string(self.core.config.get(section, option))) for -        option, d in data.config.iteritems()])) for -                     section, data in self.core.config.getBaseSections()]) +        data = {} +        for section, config, values in self.core.config.iterCoreSections(): +            holder = ConfigHolder(section, config.name, config.description, config.long_desc) +            holder.items = [ConfigItem(option, x.name, x.description, x.type, to_string(x.default), +                to_string(values.get(option, x.default))) for option, x in config.config.iteritems()] +            data[section] = holder +        return data -    def getConfigRef(self): -        """Config instance, not for RPC""" -        return self.core.config +    def getCoreConfig(self): +        """ Retrieves core config sections -    def getGlobalPlugins(self): -        """All global plugins/addons, only admin can use this +        :rtype: list of PluginInfo +        """ +        return [PluginInfo(section, config.name, config.description, False, False) +                for section, config, values in self.core.config.iterCoreSections()] -        :return: list of `ConfigInfo` +    @UserContext +    @RequirePerm(Permission.Plugins) +    def getPluginConfig(self): +        """All plugins and addons the current user has configured + +        :rtype: list of PluginInfo          """ -        pass +        # TODO: include addons that are activated by default +        data = [] +        for name, config, values in self.core.config.iterSections(self.user): +            if not values: continue +            item = PluginInfo(name, config.name, config.description, +                self.core.pluginManager.isPluginType(name, "addons"), +                self.core.pluginManager.isUserPlugin(name), +                values.get("activated", False)) +            data.append(item) + +        return data      @UserContext      @RequirePerm(Permission.Plugins) -    def getUserPlugins(self): -        """List of plugins every user can configure for himself +    def getAvailablePlugins(self): +        """List of all available plugins, that are configurable -        :return: list of `ConfigInfo` +        :rtype: list of PluginInfo          """ -        pass +        # TODO: filter user_context / addons when not allowed +        return [PluginInfo(name, config.name, config.description, +            self.core.pluginManager.isPluginType(name, "addons"), +            self.core.pluginManager.isUserPlugin(name)) +                for name, config, values in self.core.config.iterSections(self.user)]      @UserContext      @RequirePerm(Permission.Plugins)      def configurePlugin(self, plugin): -        """Get complete config options for an plugin +        """Get complete config options for desired section -        :param plugin: Name of the plugin to configure -        :return: :class:`ConfigHolder` +        :param plugin: Name of plugin or config section +        :rtype: ConfigHolder          """          pass @@ -82,7 +104,7 @@ class ConfigApi(ApiComponent):      def saveConfig(self, config):          """Used to save a configuration, core config can only be saved by admins -        :param config: :class:`ConfigHolder +        :param config: :class:`ConfigHolder`          """          pass @@ -92,9 +114,8 @@ class ConfigApi(ApiComponent):          """Deletes modified config          :param plugin: plugin name -        :return:          """ -        pass +        self.core.config.delete(plugin, self.user)      @RequirePerm(Permission.Plugins)      def setConfigHandler(self, plugin, iid, value): | 
