diff options
author | David Sommerseth <davids@redhat.com> | 2009-06-10 11:43:56 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2009-06-10 11:43:56 +0200 |
commit | b25b2ca548508cd2beb26f465b7bc5a296592461 (patch) | |
tree | 8c6db01b6ac2bd22baa6b6be1de6382244c471f9 /src/dmidecodeXML.py | |
parent | b6d42c742d89dda95cc6e371f0fda6bf1d385a45 (diff) | |
download | python-dmidecode-b25b2ca548508cd2beb26f465b7bc5a296592461.tar.gz python-dmidecode-b25b2ca548508cd2beb26f465b7bc5a296592461.tar.xz python-dmidecode-b25b2ca548508cd2beb26f465b7bc5a296592461.zip |
Implemented native libxml2 XML API for dmidecode
To use this API, you need to import dmidecodeXML. This is a wrapper class for
the internal XML API which has been implemented. In addition, you might also
want to import libxml2 as well.
dmidecodeXML::QuerySection(<string>)
Valid section strings can be found in the pymap.xml file, in the <GroupMapping>
tag section.
dmidecodeXML::TypeId(<integer between 0-255>)
Valid values should match the DMI/SMBIOS specification.
dmidecodeXML::SetResultType(resultType)
Result type can be either dmidecodeXML.DMIXML_NODE or dmidecodeXML.DMIXML_DOC
----------------------------------------------------------
import libxml2
import dmidecodeXML
dmixml = dmidecodeXML.dmidecodeXML()
section_nodes = dmixml.QuerySection('processor')
dmixml.SetResultType(dmidecodeXML.DMIXML_DOC)
typeid_doc = dmixml.QueryTypeId(0x10)
dmixml.SetResultType(dmidecodeXML.DMIXML_NODE)
typeid_doc.saveFormatFileEnc("-", "UTF-8", 1)
----------------------------------------------------------
Diffstat (limited to 'src/dmidecodeXML.py')
-rw-r--r-- | src/dmidecodeXML.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/dmidecodeXML.py b/src/dmidecodeXML.py new file mode 100644 index 0000000..93b4598 --- /dev/null +++ b/src/dmidecodeXML.py @@ -0,0 +1,62 @@ +import libxml2 +import dmidecode + +DMIXML_NODE='n' +DMIXML_DOC='d' + +class dmidecodeXML: + "Native Python API for retrieving dmidecode information as XML" + + def __init__(self): + self.restype = DMIXML_NODE; + + def SetResultType(self, type): + """ + Sets the result type of queries. The value can be DMIXML_NODE or DMIXML_DOC, + which will return an libxml2::xmlNode or libxml2::xmlDoc object, respectively + """ + + if type == DMIXML_NODE: + self.restype = DMIXML_NODE + elif type == DMIXML_DOC: + self.restype = DMIXML_DOC + else: + raise TypeError, "Invalid result type value" + return True + + def QuerySection(self, sectname): + """ + Queries the DMI data structure for a given section name. A section + can often contain several DMI type elements + """ + if self.restype == DMIXML_NODE: + ret = libxml2.xmlNode( _obj = dmidecode.xmlapi(query_type='s', + result_type=self.restype, + section=sectname) ) + elif self.restype == DMIXML_DOC: + ret = libxml2.xmlDoc( _obj = dmidecode.xmlapi(query_type='s', + result_type=self.restype, + section=sectname) ) + else: + raise TypeError, "Invalid result type value" + + return ret + + + def QueryTypeId(self, tpid): + """ + Queries the DMI data structure for a specific DMI type. + """ + if self.restype == DMIXML_NODE: + ret = libxml2.xmlNode( _obj = dmidecode.xmlapi(query_type='t', + result_type=self.restype, + typeid=tpid)) + elif self.restype == DMIXML_DOC: + ret = libxml2.xmlDoc( _obj = dmidecode.xmlapi(query_type='t', + result_type=self.restype, + typeid=tpid)) + else: + raise TypeError, "Invalid result type value" + + return ret + |