[Kimchi-devel] [PATCH 1/3] Plugins: Fix plugins framework in kimchi

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Tue Jan 14 16:17:48 UTC 2014


If the plugin tab name string is not found in kimchi i18n file, the
tab name is set as 'unknown'. This patch fixes this problem and also
adds routines to add tab html file in cherrypy configuration automati
cally.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/kimchi/server.py     | 38 ++++++++++++++++++++++++++++++++++++--
 ui/js/src/kimchi.main.js |  2 +-
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/kimchi/server.py b/src/kimchi/server.py
index b820263..919e2e0 100644
--- a/src/kimchi/server.py
+++ b/src/kimchi/server.py
@@ -28,6 +28,10 @@ import logging.handlers
 import os
 import sslcert
 
+
+from xml.etree import ElementTree
+
+
 from kimchi import auth
 from kimchi import config
 from kimchi import model
@@ -208,13 +212,43 @@ class Server(object):
                 script_name = plugin_config['kimchi']['uri']
                 del plugin_config['kimchi']
 
+                tabs_extra_file = config.get_plugin_tab_xml(plugin_name)
                 plugin_config['/ui/config/tab-ext.xml'] = {
                     'tools.staticfile.on': True,
-                    'tools.staticfile.filename':
-                    config.get_plugin_tab_xml(plugin_name),
+                    'tools.staticfile.filename': tabs_extra_file,
                     'tools.nocache.on': True}
+
+                # Providing plugin tabs htmls
+                et = ElementTree.ElementTree(file=tabs_extra_file)
+
+                tabs = et.findall('tab')
+                for tab in tabs:
+                    html = tab.find('path').text
+                    tabs_extra_file = os.path.join(config.get_prefix(), html)
+                    if html.startswith('/'):
+                        html = html.replace(script_name,'')
+                    else:
+                        html = html.replace(script_name[1:],'')
+                    plugin_config[html] = {
+                        'tools.staticfile.on': True,
+                        'tools.staticfile.filename': tabs_extra_file,
+                        'tools.nocache.on': True}
+
             except KeyError:
                 continue
+            except IOError as e:
+                msg = "Failed to load plugin tabs file %s" %tabs_extra_file
+                cherrypy.log.error_log.error(msg)
+                cherrypy.log.error_log.error('Ignoring plugin "%s"',
+                                             plugin_name)
+                continue
+            except ElementTree.ParseError as e:
+                msg = "XML parse error in file %s: %s" %(
+                          tabs_extra_file, e.msg)
+                cherrypy.log.error_log.error(msg)
+                cherrypy.log.error_log.error('Ignoring plugin "%s"',
+                                             plugin_name)
+                continue
 
             try:
                 plugin_app = import_class(plugin_class)()
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index cc8afee..8b84a34 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -211,7 +211,7 @@ kimchi.getTabHtml = function(url) {
             $(xmlData).find('tab').each(function() {
                 var $tab = $(this);
                 var titleKey = $tab.find('title').text();
-                var title = i18n[titleKey];
+                var title = i18n[titleKey] || titleKey;
                 var path = $tab.find('path').text();
                 tabsHtml += "<li><a class='item' href=" + path + ">" + title + "</a></li>";
             });
-- 
1.8.1.4




More information about the Kimchi-devel mailing list