summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-07-02 04:53:48 +0000
committernima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-07-02 04:53:48 +0000
commit0b6d2fb3e16489f5bc349e2fdc214636c478bba0 (patch)
treef36955d72899cb91ab9ad5c596b5178a7bf41ab2
parentc10adcd728be238d8579bf98075a2468f0143cc2 (diff)
downloadpython-dmidecode-0b6d2fb3e16489f5bc349e2fdc214636c478bba0.tar.gz
python-dmidecode-0b6d2fb3e16489f5bc349e2fdc214636c478bba0.tar.xz
python-dmidecode-0b6d2fb3e16489f5bc349e2fdc214636c478bba0.zip
Now the `Handle' hex codes are the key values in the python dictionaries
returned. git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@8 abc39116-655e-4be6-ad55-d661dc543056
-rw-r--r--dmidecodemodule.c37
-rwxr-xr-xexample.py14
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"); }
diff --git a/example.py b/example.py
index c7f0056..33a56ee 100755
--- a/example.py
+++ b/example.py
@@ -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())