summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rteval/dmi.py53
-rw-r--r--rteval/xmlout.py77
2 files changed, 127 insertions, 3 deletions
diff --git a/rteval/dmi.py b/rteval/dmi.py
index 73abdb1..37ef80e 100644
--- a/rteval/dmi.py
+++ b/rteval/dmi.py
@@ -6,6 +6,53 @@ import subprocess
sys.pathconf = "."
import xmlout
+typenames = {
+ 0:"BIOS Information",
+ 1:"System Information",
+ 2:"Base Board Information",
+ 3:"Chassis Information",
+ 4:"Processor Information",
+ 5:"Memory Controller Information",
+ 6:"Memory Module Information",
+ 7:"Cache Information",
+ 8:"Port Connector Information",
+ 9:"System Slots",
+ 10:"On Board Devices Information",
+ 11:"OEM Strings",
+ 12:"System Configuration Options",
+ 13:"BIOS Language Information",
+ 14:"Group Associations",
+ 15:"System Event Log",
+ 16:"Physical Memory Array",
+ 17:"Memory Device",
+ 18:"32-bit Memory Error Information",
+ 19:"Memory Array Mapped Address",
+ 20:"Memory Device Mapped Address",
+ 21:"Built-in Pointing Device",
+ 22:"Portable Battery",
+ 23:"System Reset",
+ 24:"Hardware Security",
+ 25:"System Power Controls",
+ 26:"Voltage Probe",
+ 27:"Cooling Device",
+ 28:"Temperature Probe",
+ 29:"Electrical Current Probe",
+ 30:"Out-of-Band Remote Access",
+ 31:"Boot Integrity Services (BIS) Entry Point",
+ 32:"System Boot Information",
+ 33:"64-bit Memory Error Information",
+ 34:"Management Device",
+ 35:"Management Device Component",
+ 36:"Management Device Threshold Data",
+ 37:"Memory Channel",
+ 38:"IPMI Device Information",
+ 39:"System Power Supply",
+ 40:"Additional Information",
+ 41:"Onboard Devices Extended Information",
+ 126:"Inactive",
+ 127:"End-of-Table",
+}
+
class DMIinfo(object):
'''class used to obtain DMI info via the 'dmidecode' utility'''
@@ -48,7 +95,11 @@ class DMIinfo(object):
if name:
if name.find('0x') != -1:
x.openblock('Section',
- {'handle':d['dmi_handle'], 'type':d['dmi_type'], 'size':d['dmi_size']})
+ {'handle':d['dmi_handle'],
+ 'type':d['dmi_type'],
+ 'description':typenames[int(d['dmi_type'])],
+ 'size':d['dmi_size']
+ })
del d['dmi_type']
del d['dmi_handle']
del d['dmi_size']
diff --git a/rteval/xmlout.py b/rteval/xmlout.py
index 877974e..4884511 100644
--- a/rteval/xmlout.py
+++ b/rteval/xmlout.py
@@ -5,7 +5,7 @@ import sys
import libxml2
import libxslt
import codecs
-
+import re
class XMLOut(object):
'''Class to create XML output'''
@@ -23,7 +23,7 @@ class XMLOut(object):
self.xmldoc.freeDoc()
- def __encode(self, value):
+ def __encode(self, value, tagmode = False):
if type(value) is unicode:
val = value
elif type(value) is str:
@@ -31,6 +31,10 @@ class XMLOut(object):
else:
val = unicode(str(value))
+ if tagmode is True:
+ rx = re.compile(" ")
+ val = rx.sub("_", val)
+
# libxml2 uses UTF-8 internally and must have
# all input as UTF-8.
return val.encode('utf-8')
@@ -46,6 +50,36 @@ class XMLOut(object):
tmp = tagname.replace(' ', '_')
return tmp.replace('\t', '_')
+
+ def __parseToXML(self, node, data):
+ # All supported variable types needs to be set up
+ # here. TypeError exception will be raised on
+ # unknown types.
+
+ t = type(data)
+ if t is unicode or t is str or t is int or t is float:
+ n = libxml2.newText(self.__encode(data))
+ node.addChild(n)
+ elif t is bool:
+ v = data and "1" or "0"
+ n = libxml2.newText(self.__encode(v))
+ node.addChild(n)
+ elif t is dict:
+ for (key, val) in data.iteritems():
+ node2 = libxml2.newNode(self.__encode(self.parsedata_prefix + key, True))
+ self.__parseToXML(node2, val)
+ node.addChild(node2)
+ elif t is tuple:
+ for v in data:
+ if type(v) is dict:
+ self.__parseToXML(node, v)
+ else:
+ n = libxml2.newNode(self.tuple_tagname)
+ self.__parseToXML(n, v)
+ node.addChild(n)
+ else:
+ raise TypeError, "unhandled type (%s) for value '%s'" % (type(data), unicode(data))
+
def close(self):
if self.status == 0:
raise RuntimeError, "XMLOut: No XML document is created nor loaded"
@@ -163,6 +197,19 @@ class XMLOut(object):
self.__add_attributes(ntag, attributes)
+ def ParseData(self, tagname, data, attributes=None, tuple_tagname="tuples", prefix = ""):
+ if self.status != 1:
+ raise RuntimeError, "XMLOut: taggedvalue() cannot be called before NewReport() is called"
+
+ self.tuple_tagname = self.__fixtag(tuple_tagname)
+ self.parsedata_prefix = prefix
+
+ ntag = libxml2.newNode(self.__fixtag(tagname))
+ self.__add_attributes(ntag, attributes)
+ self.__parseToXML(ntag, data)
+ self.currtag.addChild(ntag)
+
+
if __name__ == '__main__':
x = XMLOut('rteval', '0.6', None, 'UTF-8')
x.NewReport()
@@ -192,3 +239,29 @@ if __name__ == '__main__':
x.LoadReport("latency.xml", True)
x.Write("-")
x.Write("-", "rteval_text.xsl")
+ x.close()
+
+ ## Test new data parser ... it eats most data types
+ x.NewReport()
+ x.ParseData("ParseTest", "test string", {"type": "simple_string"})
+ x.ParseData("ParseTest", 1234, {"type": "integer"})
+ x.ParseData("ParseTest", 39.3904, {"type": "float"})
+ x.ParseData("ParseTest", (11,22,33,44,55), {"type": "tuples"})
+ x.ParseData("ParseTest", (99,88,77), {"type": "tuples", "comment": "Changed default tuple tag name"},
+ "int_values")
+ test = {"var1": "value 1",
+ "var2": { "varA1": 1,
+ "pi": 3.1415926,
+ "varA3": (1,
+ 2,
+ {"test1": "val1"},
+ (4.1,4.2,4.3),
+ 5),
+ "varA4": {'another_level': True,
+ 'another_value': "blabla"}
+ },
+ "utf8 data": u'æøå',
+ u"løpe": True}
+ x.ParseData("ParseTest", test, {"type": "dict"}, prefix="test ")
+ x.close()
+ x.Write("-")