diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-01-03 17:14:02 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-01-03 17:14:02 +0100 |
commit | a6b5a69612f4dd744be20c326152a9d892150f98 (patch) | |
tree | f3a221e2c8e1b805b5b83c0136978b9fb36eae59 /module/api/ConfigApi.py | |
parent | little cleanup, improved handling of custom exceptions via api (diff) | |
download | pyload-a6b5a69612f4dd744be20c326152a9d892150f98.tar.xz |
seperate api into several components
Diffstat (limited to 'module/api/ConfigApi.py')
-rw-r--r-- | module/api/ConfigApi.py | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/module/api/ConfigApi.py b/module/api/ConfigApi.py new file mode 100644 index 000000000..f3f2e6950 --- /dev/null +++ b/module/api/ConfigApi.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from module.Api import Api, UserContext, RequirePerm, Permission, ConfigHolder, ConfigItem +from module.utils import to_string + +from ApiComponent import ApiComponent + +class ConfigApi(ApiComponent): + """ Everything related to configuration """ + + def getConfigValue(self, section, option): + """Retrieve config value. + + :param section: name of category, or plugin + :param option: config option + :rtype: str + :return: config value as string + """ + value = self.core.config.get(section, option) + return to_string(value) + + def setConfigValue(self, section, option, value): + """Set new config value. + + :param section: + :param option: + :param value: new config value + """ + 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) + + def getConfig(self): + """Retrieves complete config of core. + + :rtype: ConfigHolder + :return: dict with section mapped to config + """ + # 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()]) + + + def getConfigRef(self): + """Config instance, not for RPC""" + return self.core.config + + def getGlobalPlugins(self): + """All global plugins/addons, only admin can use this + + :return: list of `ConfigInfo` + """ + pass + + @UserContext + @RequirePerm(Permission.Plugins) + def getUserPlugins(self): + """List of plugins every user can configure for himself + + :return: list of `ConfigInfo` + """ + pass + + @UserContext + @RequirePerm(Permission.Plugins) + def configurePlugin(self, plugin): + """Get complete config options for an plugin + + :param plugin: Name of the plugin to configure + :return: :class:`ConfigHolder` + """ + + pass + + @UserContext + @RequirePerm(Permission.Plugins) + def saveConfig(self, config): + """Used to save a configuration, core config can only be saved by admins + + :param config: :class:`ConfigHolder + """ + pass + + @UserContext + @RequirePerm(Permission.Plugins) + def deleteConfig(self, plugin): + """Deletes modified config + + :param plugin: plugin name + :return: + """ + pass + + @RequirePerm(Permission.Plugins) + def setConfigHandler(self, plugin, iid, value): + pass + +if Api.extend(ConfigApi): + del ConfigApi
\ No newline at end of file |