[node-patches] Change in ovirt-node[master]: Stop crashing the plugin page by optimistically parsing file...

rbarry at redhat.com rbarry at redhat.com
Wed Jul 31 21:28:41 UTC 2013


Ryan Barry has uploaded a new change for review.

Change subject: Stop crashing the plugin page by optimistically parsing files
......................................................................

Stop crashing the plugin page by optimistically parsing files

Check whether or not we can actually split on colons for the files
we find instead of trying to do so and crashing so we're not
dependent on edit-node writing metadata for the plugin page
to work.

Change-Id: Ieaf009e86b50e2a83d401f6a4dc6a2cb6c6a2e60
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=988982
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/setup/core/plugins_page.py
1 file changed, 24 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/49/17549/1

diff --git a/src/ovirt/node/setup/core/plugins_page.py b/src/ovirt/node/setup/core/plugins_page.py
index f60e043..2afa72d 100644
--- a/src/ovirt/node/setup/core/plugins_page.py
+++ b/src/ovirt/node/setup/core/plugins_page.py
@@ -20,8 +20,10 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 from ovirt.node import ui
 from ovirt.node.plugins import NodePlugin
+from ovirt.node.utils import process
 import glob
 import os
+import re
 
 """
 A plugin for a plugins page
@@ -37,7 +39,7 @@
         return "Plugins"
 
     def rank(self):
-        return 300
+        return -1
 
     def ui_content(self):
         all_plugins = self.__list_of_plugins()
@@ -125,10 +127,26 @@
             for f in os.listdir(plugin_dir):
                 if not f.endswith(".minimize"):
                     with open(plugin_dir + f) as p:
-                        lines = p.readlines()
-                        name = lines[0].strip().split(":")[1]
-                        ver = lines[1].strip().split(":")[1]
-                        install_date = lines[2].strip().replace("Install " +
-                                                                "Date:", "")
+                        if re.compile(r'Name:.*?\nVer.*:.*?\nInstall Date:.*',
+                                      re.M | re.S).match(p.read()):
+                            #Hopefully a plugin metadata file
+                            lines = p.readlines()
+                            name = lines[0].strip().split(":")[1]
+                            ver = lines[1].strip().split(":")[1]
+                            install_date = lines[2].strip().replace(
+                                "Install Date:", "")
+                        else:
+                            cmd = '/bin/rpm -qf %s/%s' % (plugin_dir, f)
+                            package = process.check_output(cmd.split(' ')
+                                                           ).strip()
+                            cmd = "rpm -q %s --qf 'NAME: %s DATE: \
+                                   %%{version}-%%{release}.%%{arch} INST: \
+                                   %%{INSTALLTIME:date}\\n'" %\
+                                (package, package)
+                            name, ver, install_date = re.match(
+                                r'NAME: (.*?) DATE: (.*?) INST: (.*)',
+                                process.check_output(cmd, shell=True).strip()
+                            ).groups()
+
                     plugin_dict[name] = (ver, install_date)
         return plugin_dict


-- 
To view, visit http://gerrit.ovirt.org/17549
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieaf009e86b50e2a83d401f6a4dc6a2cb6c6a2e60
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>



More information about the node-patches mailing list