diff options
author | David Sommerseth <davids@redhat.com> | 2009-06-10 18:57:42 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2009-06-10 18:57:42 +0200 |
commit | 65c9384ec9b6e265aba11227ffa37ae7a6a787d1 (patch) | |
tree | 63c51e604a9e4d30dbda43cced9b28a01a149e68 /dmidecode.py | |
parent | e9ae400e4dc70966bfd940c27f9a8b91d5caffa4 (diff) | |
download | python-dmidecode-65c9384ec9b6e265aba11227ffa37ae7a6a787d1.tar.gz python-dmidecode-65c9384ec9b6e265aba11227ffa37ae7a6a787d1.tar.xz python-dmidecode-65c9384ec9b6e265aba11227ffa37ae7a6a787d1.zip |
Fixed import issues with dmidecode
As we now include libxml2 and the required libxml2mod (which is used to wrap
xmlDoc and xmlNode data into Python objects), importing only dmidecode caused
a failure. If adding import libxml2 first, everything would work out fine.
To avoid this issue, due to backwards compatibility, a tiny dmidecode wrapper
is implemted as well. The dmidecode.so module is now renamed to dmidecodemodule.so,
and the wrapper is now called dmidecode.py.
To simplify things, the dmidecodeXML module introduced in commit b25b2ca548508cd2beb26f465b7bc5a296592461
is not merged into the new dmidecode.py
The constants mentioned are now called dmidecode.DMIXML_NODE and dmidecode.DMIXML_DOC
and to instantiate the dmidecodeXML class, dmidecode.dmidecodeXML() is used.
Diffstat (limited to 'dmidecode.py')
-rw-r--r-- | dmidecode.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/dmidecode.py b/dmidecode.py new file mode 100644 index 0000000..b97bb34 --- /dev/null +++ b/dmidecode.py @@ -0,0 +1,62 @@ +import libxml2 +from dmidecodemodule import * + +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 = xmlapi(query_type='s', + result_type=self.restype, + section=sectname) ) + elif self.restype == DMIXML_DOC: + ret = libxml2.xmlDoc( _obj = 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 = xmlapi(query_type='t', + result_type=self.restype, + typeid=tpid)) + elif self.restype == DMIXML_DOC: + ret = libxml2.xmlDoc( _obj = xmlapi(query_type='t', + result_type=self.restype, + typeid=tpid)) + else: + raise TypeError, "Invalid result type value" + + return ret + |