[Kimchi-devel] [PATCH] [Wok] Bug fix #176: Assume plugin URI is /plugins/<plugin-name>
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Oct 26 16:52:21 UTC 2016
Today, every plugin configuration file has a 'uri' parameter that can be
changed.
But now, the user can change the Wok base URI so there is no need
to have this kind of configuration on each plugin.
Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
src/wok/config.py.in | 5 +++++
src/wok/model/plugins.py | 3 ++-
src/wok/server.py | 6 +++---
src/wok/utils.py | 11 +----------
4 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/src/wok/config.py.in b/src/wok/config.py.in
index 46544fa..f1167f4 100644
--- a/src/wok/config.py.in
+++ b/src/wok/config.py.in
@@ -293,5 +293,10 @@ def _get_config():
config = _get_config()
+def get_base_plugin_uri(p_name):
+ return os.path.join("/", config.get("server", "server_root"),
+ "plugins", p_name)
+
+
if __name__ == '__main__':
print paths.prefix
diff --git a/src/wok/model/plugins.py b/src/wok/model/plugins.py
index 4beff44..1b8ec5e 100644
--- a/src/wok/model/plugins.py
+++ b/src/wok/model/plugins.py
@@ -21,6 +21,7 @@
import cherrypy
+from wok.config import get_base_plugin_uri
from wok.utils import get_enabled_plugins
@@ -32,4 +33,4 @@ class PluginsModel(object):
# 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()]
+ if get_base_plugin_uri(plugin) in cherrypy.tree.apps.keys()]
diff --git a/src/wok/server.py b/src/wok/server.py
index fecca48..93d28c6 100644
--- a/src/wok/server.py
+++ b/src/wok/server.py
@@ -189,9 +189,7 @@ class Server(object):
plugin_class = ('plugins.%s.%s' %
(plugin_name,
plugin_name[0].upper() + plugin_name[1:]))
- script_name = plugin_config['wok']['uri']
del plugin_config['wok']
-
plugin_config.update(PluginConfig(plugin_name))
except KeyError:
continue
@@ -229,7 +227,9 @@ class Server(object):
"error: %s" % (plugin_class, e.message)
)
- cherrypy.tree.mount(plugin_app, script_name, plugin_config)
+ cherrypy.tree.mount(plugin_app,
+ config.get_base_plugin_uri(plugin_name),
+ plugin_config)
def start(self):
# Subscribe to SignalHandler plugin
diff --git a/src/wok/utils.py b/src/wok/utils.py
index 52f6cea..9a08001 100644
--- a/src/wok/utils.py
+++ b/src/wok/utils.py
@@ -39,7 +39,7 @@ from datetime import datetime, timedelta
from multiprocessing import Process, Queue
from threading import Timer
-from wok.config import config, paths, PluginPaths
+from wok.config import paths, PluginPaths
from wok.exception import InvalidParameter, TimeoutExpired
from wok.stringutils import decode_value
@@ -71,14 +71,6 @@ def _load_plugin_conf(name):
(plugin_conf, e.message))
-def _check_plugin_relative_path(plugin_config):
- rel_path = config.get("server", "server_root")
- plugin_uri = plugin_config['wok']['uri']
- if (rel_path is not "") and (not plugin_uri.startswith(rel_path)):
- plugin_config['wok']['uri'] = rel_path + plugin_uri
- return plugin_config
-
-
def get_enabled_plugins():
plugin_dir = paths.plugins_dir
try:
@@ -90,7 +82,6 @@ def get_enabled_plugins():
plugin_config = _load_plugin_conf(name)
try:
if plugin_config['wok']['enable']:
- plugin_config = _check_plugin_relative_path(plugin_config)
yield (name, plugin_config)
except (TypeError, KeyError):
continue
--
2.7.4
More information about the Kimchi-devel
mailing list