summaryrefslogtreecommitdiffstats
path: root/rteval/dmi.py
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 /rteval/dmi.py
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>
Diffstat (limited to 'rteval/dmi.py')
-rw-r--r--rteval/dmi.py36
1 files changed, 23 insertions, 13 deletions
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):