From 65c9384ec9b6e265aba11227ffa37ae7a6a787d1 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 10 Jun 2009 18:57:42 +0200 Subject: 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. --- dmidecode.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 dmidecode.py (limited to 'dmidecode.py') 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 + -- cgit From 541ee10989640f028d777c9341c63573aac4a55f Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 10 Jun 2009 19:30:28 +0200 Subject: Discovered another issue with Python and imports The shard library got renamed to dmidecodemodule.so, and this was not clever. When you do 'import dmidecode' in Python, it will look for files in this order: dmidecode dmidecode.so dmidecodemodule.so dmidecode.py dmidecode.pyc This is of course a problem when the wrapper introduced in commit 65c9384ec9b6e265aba11227ffa37ae7a6a787d1 is called dmidecode.py, and Python attempts to load dmidecodemodule.so before dmidecode.py. To solve this, dmidecodemodule.so is now renamed to dmidecodemod.so. --- dmidecode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dmidecode.py') diff --git a/dmidecode.py b/dmidecode.py index b97bb34..30c4d92 100644 --- a/dmidecode.py +++ b/dmidecode.py @@ -1,5 +1,5 @@ import libxml2 -from dmidecodemodule import * +from dmidecodemod import * DMIXML_NODE='n' DMIXML_DOC='d' -- cgit From a8257055f3d5f474d601cb3a5cbcbdb44e2b707d Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 11 Jun 2009 13:34:26 +0200 Subject: Made sure copyright is in place and right people get their deserved credit --- dmidecode.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'dmidecode.py') diff --git a/dmidecode.py b/dmidecode.py index 30c4d92..cd37b40 100644 --- a/dmidecode.py +++ b/dmidecode.py @@ -1,3 +1,30 @@ +# +# dmidecode.py +# Module front-end for the python-dmidecode module. +# +# Copyright 2009 David Sommerseth +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# For the avoidance of doubt the "preferred form" of this code is one which +# is in an open unpatent encumbered format. Where cryptographic key signing +# forms part of the process of creating an executable the information +# including keys needed to generate an equivalently functional executable +# are deemed to be part of the source code. +# + import libxml2 from dmidecodemod import * -- cgit