diff options
-rw-r--r-- | dmidecodemodule.c | 37 | ||||
-rwxr-xr-x | example.py | 14 |
2 files changed, 43 insertions, 8 deletions
diff --git a/dmidecodemodule.c b/dmidecodemodule.c index 4748e40..92fe3d4 100644 --- a/dmidecodemodule.c +++ b/dmidecodemodule.c @@ -7,12 +7,14 @@ static PyObject* dmidecode_get(PyObject *self, char* section) { //if(!Py_IsInitialized()) // return NULL; + /* int argc = 3; char *argv[4]; argv[0] = "dmidecode"; argv[1] = "--type"; argv[2] = section; argv[3] = NULL; + */ int ret=0; /* Returned value */ int found=0; @@ -21,7 +23,7 @@ static PyObject* dmidecode_get(PyObject *self, char* section) { u8 *buf; if(sizeof(u8)!=1 || sizeof(u16)!=2 || sizeof(u32)!=4 || '\0'!=0) { - fprintf(stderr, "%s: compiler incompatibility\n", argv[0]); + fprintf(stderr, "%s: compiler incompatibility\n", "dmidecodemodule"); exit(255); } @@ -80,7 +82,38 @@ exit_free: //. FIXME: Why does this cause crash? free(opt.type); - return PyUnicode_Splitlines(Py_BuildValue("s", buffer), 1); + /* + PyObject* raw = PyUnicode_Splitlines(Py_BuildValue("s", buffer), 1); + int i; + char* nextLine; + for(i=0; i<PyList_Size(raw); i++) { + nextLine = PyString_AS_STRING(PySequence_ITEM(raw, i)); + if(strstr(nextLine, "Handle") != NULL) { + printf("woohoo!: %s\n", nextLine); + } else { + printf(" --> %i %s\n", i, nextLine); + } + }*/ + + PyObject* data = PyDict_New(); + + char *nextLine = strtok(buffer, "\n"); + PyObject* s = NULL; + PyObject* d = NULL; + PyObject* key = NULL; + while(nextLine != NULL) { + if(memcmp(nextLine, "Handle", 6) == 0) { + key = PyInt_FromLong(strtol(nextLine+7, NULL, 16)); + d = PyList_New(0); + PyDict_SetItem(data, key, d); + } else if(key) { + s = Py_BuildValue("s", nextLine); + PyList_Append(d, s); + } + nextLine = strtok(NULL, "\n"); + } + + return data; } static PyObject* dmidecode_get_bios(PyObject *self, PyObject *args) { return dmidecode_get(self, "bios"); } @@ -1,14 +1,16 @@ #!/usr/bin/python def l(x): + for k in x.keys(): + print " %x"%k, "==>", len(x[k]) return len(x) import dmidecode, time print(dir(dmidecode)) -print "proc", l(dmidecode.processor()) -print "sys", l(dmidecode.system()) -print "bios", l(dmidecode.bios()) -print "proc", l(dmidecode.processor()) -print "sys", l(dmidecode.system()) -print "bios", l(dmidecode.bios()) +print "proc\n", l(dmidecode.processor()) +print "sys\n", l(dmidecode.system()) +print "bios\n", l(dmidecode.bios()) +print "proc\n", l(dmidecode.processor()) +print "sys\n", l(dmidecode.system()) +print "bios\n", l(dmidecode.bios()) |