diff options
author | nima <nima@abc39116-655e-4be6-ad55-d661dc543056> | 2008-07-01 06:01:21 +0000 |
---|---|---|
committer | nima <nima@abc39116-655e-4be6-ad55-d661dc543056> | 2008-07-01 06:01:21 +0000 |
commit | eb7958574ce98601433022d7d23343025c1e34b8 (patch) | |
tree | 2f9f0003beaff39d40a0f836ee035de330cea4de /dmidecodemodule.c | |
parent | 4f5bfc68e416a7d1e6264e43278fe9b9df684eed (diff) | |
download | python-dmidecode-eb7958574ce98601433022d7d23343025c1e34b8.tar.gz python-dmidecode-eb7958574ce98601433022d7d23343025c1e34b8.tar.xz python-dmidecode-eb7958574ce98601433022d7d23343025c1e34b8.zip |
Project progressing along excellently. The python module is now functional and
has as many methods as the --type option takes.
Next is to expand and harness the code around the `--string' option.
git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@3 abc39116-655e-4be6-ad55-d661dc543056
Diffstat (limited to 'dmidecodemodule.c')
-rw-r--r-- | dmidecodemodule.c | 97 |
1 files changed, 71 insertions, 26 deletions
diff --git a/dmidecodemodule.c b/dmidecodemodule.c index 7ef9caf..a4ea48f 100644 --- a/dmidecodemodule.c +++ b/dmidecodemodule.c @@ -1,6 +1,54 @@ #include "dmidecodemodule.h" -static PyObject* dmidecode_get(PyObject *self, PyObject *args) { +static PyObject* dmidecode_get(PyObject *self, char* section) { + bzero(buffer, 50000); + + PyObject *list = PyList_New(0); + + char *argv[4]; + argv[0] = "dmidecode"; + argv[1] = "--type"; + argv[2] = section; + argv[3] = NULL; + + submain(3, argv); + PyList_Append(list, PyUnicode_Splitlines(Py_BuildValue("s", buffer), 1)); + return list; +} + +static PyObject* dmidecode_get_bios(PyObject *self, PyObject *args) { return dmidecode_get(self, "bios"); } +static PyObject* dmidecode_get_system(PyObject *self, PyObject *args) { return dmidecode_get(self, "system"); } +static PyObject* dmidecode_get_baseboard(PyObject *self, PyObject *args) { return dmidecode_get(self, "baseboard"); } +static PyObject* dmidecode_get_chassis(PyObject *self, PyObject *args) { return dmidecode_get(self, "chassis"); } +static PyObject* dmidecode_get_processor(PyObject *self, PyObject *args) { return dmidecode_get(self, "processor"); } +static PyObject* dmidecode_get_memory(PyObject *self, PyObject *args) { return dmidecode_get(self, "memory"); } +static PyObject* dmidecode_get_cache(PyObject *self, PyObject *args) { return dmidecode_get(self, "cache"); } +static PyObject* dmidecode_get_connector(PyObject *self, PyObject *args) { return dmidecode_get(self, "connector"); } +static PyObject* dmidecode_get_slot(PyObject *self, PyObject *args) { return dmidecode_get(self, "slot"); } + +PyMethodDef DMIDataMethods[] = { + { "bios", dmidecode_get_bios, METH_VARARGS, "BIOS Data" }, + { "system", dmidecode_get_system, METH_VARARGS, "System Data" }, + { "baseboard", dmidecode_get_baseboard, METH_VARARGS, "Baseboard Data" }, + { "chassis", dmidecode_get_chassis, METH_VARARGS, "Chassis Data" }, + { "processor", dmidecode_get_processor, METH_VARARGS, "Processor Data" }, + { "memory", dmidecode_get_memory, METH_VARARGS, "Memory Data" }, + { "cache", dmidecode_get_cache, METH_VARARGS, "Cache Data" }, + { "connector", dmidecode_get_connector, METH_VARARGS, "Connector Data" }, + { "slot", dmidecode_get_slot, METH_VARARGS, "Slot Data" }, + { NULL, NULL, 0, NULL } +}; + + +PyMODINIT_FUNC initdmidecode(void) { + (void) Py_InitModule("dmidecode", DMIDataMethods); +} + + +/* +static PyObject* dmidecode_xget(PyObject *self, PyObject *args) { + bzero(buffer, 50000); + PyObject *list = PyList_New(0); //const char *command; @@ -9,39 +57,36 @@ static PyObject* dmidecode_get(PyObject *self, PyObject *args) { //for(i=0; i<len(args); i++) // PyList_Append(list, Py_BuildValue("s", args[i])); - PyList_Append(list, PyInt_FromLong(3)); - PyList_Append(list, PyInt_FromLong(4)); + // PyList_Append(list, PyInt_FromLong(3)); + // PyList_Append(list, PyInt_FromLong(4)); //PyList_Append(list, Py_BuildValue("s", command)); - PyList_Append(list, Py_BuildValue("i", PySequence_Size(args))); int i; - int argc = PySequence_Size(args); - char *argv[argc]; - for(i=0; i<argc; i++) { - argv[i] = PyString_AS_STRING(PySequence_ITEM(args, i)); - printf(">> %s <<\n", argv[i]); - PyList_Append(list, PySequence_ITEM(args, i)); + int argc = PySequence_Size(args) + 1; //. 1 for $0, 1 for trailing NULL + char *argv[argc+1]; + argv[0] = "dmidecode"; + for(i=1; i<argc; i++) { + argv[i] = PyString_AS_STRING(PySequence_ITEM(args, i-1)); + PyList_Append(list, PySequence_ITEM(args, i-1)); } - bzero(buffer, 50000); - //submain(buffer, argc, argv); + argv[argc] = NULL; - return list; -} - -PyMethodDef DMIDataMethods[] = { - { "dmidecode", dmidecode_get, METH_VARARGS, "Get hardware data as a list" }, - { NULL, NULL, 0, NULL } -}; + for(i=0; i<argc; i++) printf(">>> %d: %s\n", i, argv[i]); + submain(buffer, argc, argv); + PyList_Append(list, PyUnicode_Splitlines(Py_BuildValue("s", buffer), 1)); + //PyList_Append(list, PySequence_List(args)); + //PyList_Append(list, Py_BuildValue("i", PySequence_Size(args))); -PyMODINIT_FUNC initdmidecode(void) { - (void) Py_InitModule("dmidecode", DMIDataMethods); + return list; } +*/ +/* int submain(char* buffer, int argc, char * const argv[]) { - int ret=0; /* Returned value */ + int ret=0; /* Returned value * / int found=0; size_t fp; int efi; @@ -53,7 +98,7 @@ int submain(char* buffer, int argc, char * const argv[]) exit(255); } - /* Set default option values */ + /* Set default option values * / opt.devmem=DEFAULT_MEM_DEV; opt.flags=0; @@ -78,7 +123,7 @@ int submain(char* buffer, int argc, char * const argv[]) if(!(opt.flags & FLAG_QUIET)) printf("# dmidecode %s\n", VERSION); - /* First try EFI (ia64, Intel-based Mac) */ + /* First try EFI (ia64, Intel-based Mac) * / efi=address_from_efi(&fp); switch(efi) { @@ -100,7 +145,7 @@ int submain(char* buffer, int argc, char * const argv[]) goto done; memory_scan: - /* Fallback to memory scan (x86, x86_64) */ + /* Fallback to memory scan (x86, x86_64) * / if((buf=mem_chunk(0xF0000, 0x10000, opt.devmem))==NULL) { ret=1; @@ -131,6 +176,6 @@ done: exit_free: free(opt.type); - printf("%s\n", buffer); return ret; } +*/ |