[Kimchi-devel] [PATCH][Wok 4/5] Implements control/model of new plugin API
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Jun 1 03:17:50 UTC 2016
On 05/31/2016 02:51 PM, Rodrigo Trujillo wrote:
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
> ---
> src/wok/control/plugins.py | 19 ++++++++++++++++---
> src/wok/i18n.py | 3 +++
> src/wok/model/plugins.py | 30 ++++++++++++++++++++++++------
> 3 files changed, 43 insertions(+), 9 deletions(-)
>
> diff --git a/src/wok/control/plugins.py b/src/wok/control/plugins.py
> index 57dfa1b..c7c9554 100644
> --- a/src/wok/control/plugins.py
> +++ b/src/wok/control/plugins.py
> @@ -19,11 +19,24 @@
> # License along with this library; if not, write to the Free Software
> # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>
> -from wok.control.base import SimpleCollection
> +from wok.control.base import Collection, Resource
> from wok.control.utils import UrlSubNode
>
>
> - at UrlSubNode("plugins")
> -class Plugins(SimpleCollection):
> + at UrlSubNode("pluginsmanager")
> +class Plugins(Collection):
> def __init__(self, model):
> super(Plugins, self).__init__(model)
> + self.resource = Plugin
> +
> +
> +class Plugin(Resource):
> + def __init__(self, model, id):
> + super(Plugin, self).__init__(model, id)
> + self.uri_fmt = "/pluginsmanager/%s"
> + self.enable = self.generate_action_handler('enable')
> + self.disable = self.generate_action_handler('disable')
> +
> + @property
> + def data(self):
> + return self.info
Please, set admin_methods to avoid any user be able to change the plugin
settings.
And also update test_authorization.py tests to cover that.
> diff --git a/src/wok/i18n.py b/src/wok/i18n.py
> index 4fc21f1..bda3949 100644
> --- a/src/wok/i18n.py
> +++ b/src/wok/i18n.py
> @@ -60,4 +60,7 @@ messages = {
> "WOKRES0001L": _("Request made on resource"),
> "WOKROOT0001L": _("User '%(username)s' logged in"),
> "WOKROOT0002L": _("User '%(username)s' logged out"),
> +
> + "WOKPLUG0001E": _("Plugin '%(plugin_name)s' not found."),
> + "WOKPLUG0002E": _("Error updating configuration file of plugin '%(plugin)s'."),
> }
> diff --git a/src/wok/model/plugins.py b/src/wok/model/plugins.py
> index 4beff44..1842dbc 100644
> --- a/src/wok/model/plugins.py
> +++ b/src/wok/model/plugins.py
> @@ -19,9 +19,9 @@
> # License along with this library; if not, write to the Free Software
> # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>
> -import cherrypy
>
> -from wok.utils import get_enabled_plugins
> +from wok.exception import NotFoundError
> +from wok.pluginsmanager import Plugins
>
>
> class PluginsModel(object):
> @@ -29,7 +29,25 @@ class PluginsModel(object):
> pass
>
> def get_list(self):
> - # Will only return plugins that were loaded correctly by WOK and are
> - # properly configured in cherrypy
> - return [plugin for (plugin, config) in get_enabled_plugins()
> - if config.get('wok').get('uri') in cherrypy.tree.apps.keys()]
> + return Plugins().get_all_plugins_names()
> +
> +
> +class PluginModel(object):
> + def __init__(self, **kargs):
> + pass
> +
> + def lookup(self, plugin):
> + info = Plugins().get_plugin_info(plugin)
> + if not info:
> + raise NotFoundError('WOKPLUG0001E', {'plugin_name': plugin})
> +
> + return {'name': plugin,
> + 'enabled': info['enabled']}
> +
> + def enable(self, plugin_name):
> + print "Enabling %s" % plugin_name
> + Plugins().enable_plugin(plugin_name)
> +
> + def disable(self, plugin_name):
> + print "Disabling %s" % plugin_name
> + Plugins().disable_plugin(plugin_name)
Please, use wok_log instead of print
More information about the Kimchi-devel
mailing list