summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2009-06-10 18:57:42 +0200
committerDavid Sommerseth <davids@redhat.com>2009-06-10 18:57:42 +0200
commit65c9384ec9b6e265aba11227ffa37ae7a6a787d1 (patch)
tree63c51e604a9e4d30dbda43cced9b28a01a149e68
parente9ae400e4dc70966bfd940c27f9a8b91d5caffa4 (diff)
downloadpython-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.
-rw-r--r--dmidecode.py (renamed from src/dmidecodeXML.py)10
-rw-r--r--src/dmidecodemodule.c4
-rw-r--r--src/setup.py5
l---------unit-tests/dmidecode.py1
-rwxr-xr-xunit-tests/unit23
5 files changed, 22 insertions, 21 deletions
diff --git a/src/dmidecodeXML.py b/dmidecode.py
index 93b4598..b97bb34 100644
--- a/src/dmidecodeXML.py
+++ b/dmidecode.py
@@ -1,5 +1,5 @@
import libxml2
-import dmidecode
+from dmidecodemodule import *
DMIXML_NODE='n'
DMIXML_DOC='d'
@@ -30,11 +30,11 @@ class dmidecodeXML:
can often contain several DMI type elements
"""
if self.restype == DMIXML_NODE:
- ret = libxml2.xmlNode( _obj = dmidecode.xmlapi(query_type='s',
+ ret = libxml2.xmlNode( _obj = xmlapi(query_type='s',
result_type=self.restype,
section=sectname) )
elif self.restype == DMIXML_DOC:
- ret = libxml2.xmlDoc( _obj = dmidecode.xmlapi(query_type='s',
+ ret = libxml2.xmlDoc( _obj = xmlapi(query_type='s',
result_type=self.restype,
section=sectname) )
else:
@@ -48,11 +48,11 @@ class dmidecodeXML:
Queries the DMI data structure for a specific DMI type.
"""
if self.restype == DMIXML_NODE:
- ret = libxml2.xmlNode( _obj = dmidecode.xmlapi(query_type='t',
+ ret = libxml2.xmlNode( _obj = xmlapi(query_type='t',
result_type=self.restype,
typeid=tpid))
elif self.restype == DMIXML_DOC:
- ret = libxml2.xmlDoc( _obj = dmidecode.xmlapi(query_type='t',
+ ret = libxml2.xmlDoc( _obj = xmlapi(query_type='t',
result_type=self.restype,
typeid=tpid))
else:
diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c
index 846d565..032a189 100644
--- a/src/dmidecodemodule.c
+++ b/src/dmidecodemodule.c
@@ -676,7 +676,7 @@ void destruct_options(void *ptr)
}
-PyMODINIT_FUNC initdmidecode(void)
+PyMODINIT_FUNC initdmidecodemodule(void)
{
char *dmiver = NULL;
PyObject *module = NULL;
@@ -689,7 +689,7 @@ PyMODINIT_FUNC initdmidecode(void)
opt = (options *) malloc(sizeof(options)+2);
memset(opt, 0, sizeof(options)+2);
init(opt);
- module = Py_InitModule3((char *)"dmidecode", DMIDataMethods,
+ module = Py_InitModule3((char *)"dmidecodemodule", DMIDataMethods,
"Python extension module for dmidecode");
version = PyString_FromString("3.10.6");
diff --git a/src/setup.py b/src/setup.py
index 54b0357..b45775a 100644
--- a/src/setup.py
+++ b/src/setup.py
@@ -11,7 +11,7 @@ setup(
data_files = [ ('share/python-dmidecode', ['src/pymap.xml']) ],
ext_modules = [
Extension(
- "dmidecode",
+ "dmidecodemodule",
sources = [
"src/dmidecodemodule.c",
"src/util.c",
@@ -25,5 +25,6 @@ setup(
library_dirs = [ "/home/nima/dev-room/projects/dmidecode", "/usr/lib64/python2.5/site-packages"],
libraries = [ "util", "xml2", "xml2mod" ]
)
- ]
+ ],
+ py_modules = [ "dmidecode" ]
)
diff --git a/unit-tests/dmidecode.py b/unit-tests/dmidecode.py
new file mode 120000
index 0000000..4876cd6
--- /dev/null
+++ b/unit-tests/dmidecode.py
@@ -0,0 +1 @@
+../dmidecode.py \ No newline at end of file
diff --git a/unit-tests/unit b/unit-tests/unit
index b6018f9..8156945 100755
--- a/unit-tests/unit
+++ b/unit-tests/unit
@@ -64,8 +64,8 @@ def test(r, msg=None, indent=1):
sys.stdout.write(LINE)
sys.stdout.write(" * Testing for dmidecode (upstream)...")
-d = True in [os.path.exists(os.path.join(_, "dmidecode")) for _ in os.getenv("PATH").split(':')]
-test(d)
+dmidecode_bin = True in [os.path.exists(os.path.join(_, "dmidecode")) for _ in os.getenv("PATH").split(':')]
+test(dmidecode_bin)
sys.stdout.write(" * Creation of temporary files...")
try:
@@ -77,13 +77,12 @@ except:
failed()
sys.stdout.write(LINE)
-sys.stdout.write(" * Importing module...")
try:
+ sys.stdout.write(" * Importing module...")
import libxml2
import dmidecode
- import dmidecodeXML
-
passed()
+
sys.stdout.write(" * Version: %s\n"%blue(dmidecode.version))
sys.stdout.write(" * DMI Version String: %s\n"%blue(dmidecode.dmi))
@@ -153,7 +152,7 @@ try:
sys.stdout.write(" * Testing type %s..."%red(i)); sys.stdout.flush()
try:
output = dmidecode.type(i)
- if dmidecode:
+ if dmidecode_bin:
_output = commands.getoutput("dmidecode -t %d"%i).strip().split('\n')
test(len(_output) == 1 and len(output) == 0 or True)
else:
@@ -165,7 +164,7 @@ try:
except LookupError, e:
failed(e, 2)
- dmixml = dmidecodeXML.dmidecodeXML()
+ dmixml = dmidecode.dmidecodeXML()
try:
sys.stdout.write(" * XML: Swapping result type dmidecodeXML::SetResultType('-')...");
sys.stdout.flush()
@@ -178,12 +177,12 @@ try:
failed()
try:
- sys.stdout.write(" * XML: Swapping result type - dmidecodeXML::SetResultType(dmidecodeXML.DMIXML_DOC)...");
+ sys.stdout.write(" * XML: Swapping result type - dmidecodeXML::SetResultType(dmidecode.DMIXML_DOC)...");
sys.stdout.flush()
- test(dmixml.SetResultType(dmidecodeXML.DMIXML_DOC))
- sys.stdout.write(" * XML: Swapping result type - dmidecodeXML::SetResultType(dmidecodeXML.DMIXML_NODE)...");
+ test(dmixml.SetResultType(dmidecode.DMIXML_DOC))
+ sys.stdout.write(" * XML: Swapping result type - dmidecodeXML::SetResultType(dmidecode.DMIXML_NODE)...");
sys.stdout.flush()
- test(dmixml.SetResultType(dmidecodeXML.DMIXML_NODE))
+ test(dmixml.SetResultType(dmidecode.DMIXML_NODE))
except:
failed()
@@ -216,7 +215,7 @@ try:
except:
failed()
- dmixml.SetResultType(dmidecodeXML.DMIXML_DOC)
+ dmixml.SetResultType(dmidecode.DMIXML_DOC)
i = 0
for section in sections:
i += 1