summaryrefslogtreecommitdiffstats
path: root/module/api
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-01-06 15:54:52 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-01-06 15:54:52 +0100
commit6f8b5347dfa119a3df21f4ca8ba8c2b1537a726a (patch)
tree627c4d99f0aaa4c8022b70b3ebe72f201d924dd6 /module/api
parentremoved unneeded stuff (diff)
downloadpyload-6f8b5347dfa119a3df21f4ca8ba8c2b1537a726a.tar.xz
first working parts of config api
Diffstat (limited to 'module/api')
-rw-r--r--module/api/ApiComponent.py7
-rw-r--r--module/api/ConfigApi.py77
2 files changed, 55 insertions, 29 deletions
diff --git a/module/api/ApiComponent.py b/module/api/ApiComponent.py
index ba96b3be9..a89e3e0a5 100644
--- a/module/api/ApiComponent.py
+++ b/module/api/ApiComponent.py
@@ -7,11 +7,16 @@ from module.remote.ttypes import Iface
Iface = object
class ApiComponent(Iface):
- def __init__(self, core):
+ __slots__ = []
+
+ def __init__(self, core, user):
# Only for auto completion, this class can not be instantiated
from pyload import Core
+ from module.datatypes.User import User
assert isinstance(core, Core)
assert issubclass(ApiComponent, Iface)
self.core = core
+ assert isinstance(user, User)
+ self.user = user
# No instantiating!
raise Exception() \ No newline at end of file
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):