summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2013-03-12 21:01:19 +0100
committerDavid Sommerseth <davids@redhat.com>2013-03-12 21:04:51 +0100
commit19398af35587726ff5165f3cf040b55fd71e815e (patch)
tree8736ab791d1948ee2dbe4636c6017fa1b79d2a8e
parent9c836c88614f90ddd8084be312fb7726086c2d08 (diff)
downloadrteval-master.tar.gz
rteval-master.tar.xz
rteval-master.zip
Migrated from libxslt to lxmlHEADmaster
To avoid depending on libxslt-python, use the more standard Python lxml module for XSLT processing. Signed-off-by: David Sommerseth <davids@redhat.com>
-rw-r--r--README7
-rw-r--r--doc/installing.txt10
-rw-r--r--rteval.spec7
-rw-r--r--rteval/dmi.py36
-rw-r--r--rteval/xmlout.py49
5 files changed, 80 insertions, 29 deletions
diff --git a/README b/README
index feabf10..eb034c2 100644
--- a/README
+++ b/README
@@ -25,12 +25,15 @@ python-schedtils
python-ethtools
git://git.kernel.org/pub/scm/linux/kernel/git/acme/python-ethtool.git
-libxslt-python
- http://xmlsoft.org/XSLT/python.html
+python-lxml
+ http://lxml.de/
python-dmidecode
http://www.ohloh.net/p/python-dmidecode
+libxml2-python
+ http://xmlsoft.org/
+
rt-tests
git://git.kernel.org/pub/scm/linux/kernel/git/clrkwllms/rt-tests.git
diff --git a/doc/installing.txt b/doc/installing.txt
index c202902..c592e9c 100644
--- a/doc/installing.txt
+++ b/doc/installing.txt
@@ -9,14 +9,18 @@ python-ethtool
A python library to query network interfaces
git://git.kernel.org/pub/scm/linux/kernel/git/acme/python-ethtool.git
-libxslt-python
- A python library to parse XSLT stylesheets
- http://www.xmlsoft.org/XSLT/python.html
+python-lxml
+ A python library to parse XML files and XSLT stylesheets
+ http://lxml.de/
python-dmidecode
A python library used to access DMI table information
http://www.autonomy.net.au/display/pydmi/Home
+libxml2-python
+ A python library to parse XML files
+ http://xmlsoft.org/
+
rt-tests
A collection of programs used to measure real-time behavior
git://git.kernel.org/pub/scm/linux/kernel/git/clrkwllms/rt-tests.git
diff --git a/rteval.spec b/rteval.spec
index 6903b8c..cae7823 100644
--- a/rteval.spec
+++ b/rteval.spec
@@ -3,7 +3,7 @@
Name: rteval
Version: 1.37
-Release: 1%{?dist}
+Release: 2%{?dist}
Summary: Utility to evaluate system suitability for RT Linux
Group: Development/Tools
@@ -14,7 +14,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: python
Requires: python
-Requires: python-schedutils python-ethtool libxslt-python >= 1.1.17
+Requires: python-schedutils python-ethtool python-lxml
Requires: python-dmidecode >= 3.10
Requires: rt-tests >= 0.65
Requires: rteval-loads >= 1.2
@@ -71,6 +71,9 @@ rm -rf $RPM_BUILD_ROOT
/usr/bin/rteval
%changelog
+* Tue Mar 12 2013 David Sommerseth <davids@redhat.com> - 1.37-2
+- Migrated from libxslt-python to python-lxml
+
* Thu Dec 13 2012 Clark Williams <williams@redhat.com> - 1.37-1
- added module specific command line options
- From Raphaƫl Beamonte <raphael.beamonte@gmail.com>:
diff --git a/rteval/dmi.py b/rteval/dmi.py
index d317c3c..87fd639 100644
--- a/rteval/dmi.py
+++ b/rteval/dmi.py
@@ -30,7 +30,7 @@ import subprocess
sys.pathconf = "."
import xmlout
import libxml2
-import libxslt
+import lxml.etree
try:
import dmidecode
@@ -68,7 +68,7 @@ class DMIinfo(object):
'''class used to obtain DMI info via python-dmidecode'''
def __init__(self, config):
- self.version = '0.3'
+ self.version = '0.4'
self.smbios = None
self.sharedir = config.installdir
@@ -78,26 +78,36 @@ class DMIinfo(object):
self.dmixml = dmidecode.dmidecodeXML()
self.smbios = dmidecode.dmi.replace('SMBIOS ', '').replace(' present', '')
- xsltdoc = self.__load_xslt('rteval_dmi.xsl')
- self.xsltparser = libxslt.parseStylesheetDoc(xsltdoc)
+ self.xsltparser = self.__load_xslt('rteval_dmi.xsl')
def __load_xslt(self, fname):
+ ret = None
+ xsltfile = None
if os.path.exists(fname):
- return libxml2.parseFile(fname)
+ xsltfile = open(fname, "r")
elif os.path.exists(self.sharedir + '/' + fname):
- return libxml2.parseFile(self.sharedir + '/' + fname)
- else:
- raise RuntimeError, 'Could not locate XSLT template for DMI data (%s)' % fname
+ xsltfile = open(self.sharedir + '/' + fname, "r")
+
+ if xsltfile:
+ xsltdoc = lxml.etree.parse(xsltfile)
+ ret = lxml.etree.XSLT(xsltdoc)
+ xsltfile.close()
+
+ if ret is None:
+ raise RuntimeError, 'Could not locate XSLT template for DMI data (%s)' % (self.sharedir + '/' + fname)
+ return ret
+
def genxml(self, xml):
if hasattr(dmidecode, "fake"):
return
self.dmixml.SetResultType(dmidecode.DMIXML_DOC)
- resdoc = self.xsltparser.applyStylesheet(self.dmixml.QuerySection('all'), None)
- node = resdoc.getRootElement().copyNode(1)
- node.newProp("DMIinfo_version", self.version)
- xml.AppendXMLnodes(node)
+ dmiqry = xmlout.convert_libxml2_to_lxml_doc(self.dmixml.QuerySection('all'))
+ resdoc = self.xsltparser(dmiqry)
+ root = resdoc.getroot()
+ root.attrib["DMIinfo_version"] = str(self.version)
+ xml.AppendXMLnodes(xmlout.convert_lxml_to_libxml2_nodes(resdoc))
def unit_test(rootdir):
@@ -105,7 +115,7 @@ def unit_test(rootdir):
class unittest_ConfigDummy(object):
def __init__(self, rootdir):
- self.config = {'installdir': '%s/rteval'}
+ self.config = {'installdir': '/usr/share/rteval'}
self.__update_vars()
def __update_vars(self):
diff --git a/rteval/xmlout.py b/rteval/xmlout.py
index a9a9562..e013390 100644
--- a/rteval/xmlout.py
+++ b/rteval/xmlout.py
@@ -26,11 +26,35 @@
import os
import sys
import libxml2
-import libxslt
+import lxml.etree
import codecs
import re
from string import maketrans
+
+def convert_libxml2_to_lxml_doc(inxml):
+ "Converts a libxml2.xmlDoc into a lxml.etree document object"
+
+ if not isinstance(inxml, libxml2.xmlDoc):
+ raise TypeError('Function requires an libxml2.xmlDoc as input')
+
+ root = inxml.getRootElement()
+ ret = lxml.etree.XML(root.serialize('UTF-8'))
+ del root
+ return ret
+
+
+
+def convert_lxml_to_libxml2_nodes(inlxml):
+ "Converts a lxml.etree elements tree into a libxml2.xmlNode object"
+
+ if not isinstance(inlxml,lxml.etree._Element) and not isinstance(inlxml, lxml.etree._XSLTResultTree):
+ raise TypeError('Function requires an lxml.etree object as input')
+
+ return libxml2.parseDoc(lxml.etree.tostring(inlxml)).getRootElement()
+
+
+
class XMLOut(object):
'''Class to create XML output'''
def __init__(self, roottag, version, attr = None, encoding='UTF-8'):
@@ -171,6 +195,7 @@ class XMLOut(object):
self.status = 2 # Confirm that we have loaded a report from file
+
def Write(self, filename, xslt = None):
if self.status != 2 and self.status != 3:
raise RuntimeError, "XMLOut: XML document is not closed"
@@ -181,8 +206,10 @@ class XMLOut(object):
return
else:
# Load XSLT file and prepare the XSLT parser
- xsltdoc = libxml2.parseFile(xslt)
- parser = libxslt.parseStylesheetDoc(xsltdoc)
+ xsltfile = open(xslt, 'r')
+ xsltdoc = lxml.etree.parse(xsltfile)
+ parser = lxml.etree.XSLT(xsltdoc)
+ xsltfile.close()
# imitate libxml2's filename interpretation
if filename != "-":
@@ -192,18 +219,22 @@ class XMLOut(object):
#
# Parse XML+XSLT and write the result to file
#
- resdoc = parser.applyStylesheet(self.xmldoc, None)
- # Decode the result string according to the charset declared in the XSLT file
- xsltres = parser.saveResultToString(resdoc).decode(parser.encoding())
+ xmldoc = convert_libxml2_to_lxml_doc(self.xmldoc)
+ resdoc = parser(xmldoc)
+
# Write the file with the requested output encoding
- dstfile.write(xsltres.encode(self.encoding))
+ dstfile.write(unicode(resdoc).encode(self.encoding))
if dstfile != sys.stdout:
dstfile.close()
# Clean up
- resdoc.freeDoc()
- xsltdoc.freeDoc()
+ del resdoc
+ del xsltdoc
+ del parser
+ del xsltfile
+ del xmldoc
+
def GetXMLdocument(self):
if self.status != 2 and self.status != 3: