summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-07-01 06:01:21 +0000
committernima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-07-01 06:01:21 +0000
commiteb7958574ce98601433022d7d23343025c1e34b8 (patch)
tree2f9f0003beaff39d40a0f836ee035de330cea4de
parent4f5bfc68e416a7d1e6264e43278fe9b9df684eed (diff)
downloadpython-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
-rw-r--r--Makefile4
-rw-r--r--dmidecode.c4
-rw-r--r--dmidecodemodule.c97
-rw-r--r--dmidecodemodule.h2
-rw-r--r--dmiopt.c2
-rw-r--r--setup.py16
-rw-r--r--test.c109
7 files changed, 101 insertions, 133 deletions
diff --git a/Makefile b/Makefile
index ac1b870..36a5db5 100644
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,10 @@ PROGRAMS != echo dmidecode ; test `uname -m 2>/dev/null` != ia64 && echo biosdec
all : $(PROGRAMS)
python setup.py clean
python setup.py build
+ #sudo python setup.py install
+ #python -c 'import dmidecode'
+ #ldd /usr/lib/python2.4/site-packages/dmidecode.so
+ gcc -pthread -shared -fPIC build/temp.linux-i686-2.4/dmidecodemodule.o -L. -I/usr/include/python2.4 catsprintf.o dmidecode.o dmiopt.o dmioem.o util.o -o build/lib.linux-i686-2.4/dmidecode.so
sudo python setup.py install
ldd /usr/lib/python2.4/site-packages/dmidecode.so
python -c 'import dmidecode'
diff --git a/dmidecode.c b/dmidecode.c
index 966b0d5..974f3f0 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -4042,8 +4042,7 @@ int address_from_efi(size_t *address)
return ret;
}
-#ifdef SO
-int main(int argc, char * const argv[])
+int submain(int argc, char * const argv[])
{
int ret=0; /* Returned value */
int found=0;
@@ -4137,4 +4136,3 @@ exit_free:
return ret;
}
-#endif
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;
}
+*/
diff --git a/dmidecodemodule.h b/dmidecodemodule.h
index 3d555c5..cf747de 100644
--- a/dmidecodemodule.h
+++ b/dmidecodemodule.h
@@ -33,5 +33,5 @@ extern void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem);
extern int smbios_decode(u8 *buf, const char *devmem);
extern int legacy_decode(u8 *buf, const char *devmem);
extern void *mem_chunk(size_t base, size_t len, const char *devmem);
-
+extern int main(int argc, char* const argv[]);
diff --git a/dmiopt.c b/dmiopt.c
index d571108..1b583a6 100644
--- a/dmiopt.c
+++ b/dmiopt.c
@@ -169,6 +169,8 @@ static const struct string_keyword opt_string_keyword[]={
{ "processor-manufacturer", 4, 0x07, NULL, NULL },
{ "processor-version", 4, 0x10, NULL, NULL },
{ "processor-frequency", 4, 0x16, NULL, dmi_processor_frequency },
+
+ { "processor-max-frequency", 4, 0x14, NULL, dmi_processor_frequency },
};
static void print_opt_string_list(void)
diff --git a/setup.py b/setup.py
index ca193c0..25f3e98 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,15 @@
from distutils.core import setup, Extension
-setup(name = "DMIDecode",
- version = "1.0",
- ext_modules = [Extension("dmidecode", ["dmidecodemodule.c"])])
+setup(
+ name = "DMIDecode",
+ version = "1.0",
+ description = "A python module rewrite of dmidecode",
+ author = "Nima Talebi",
+ author_email = "nima@autonomy.net.au",
+ url = "http://projects/autonomy.net.au/dmidecode/",
+ ext_modules = [
+ Extension(
+ "dmidecode", ["dmidecodemodule.c"], library_dirs=["/home/nima/dev-room/projects/dmidecode"], libraries=["util"]
+ )
+ ]
+)
diff --git a/test.c b/test.c
index 1b86b2f..b200316 100644
--- a/test.c
+++ b/test.c
@@ -1,3 +1,5 @@
+#include <Python.h>
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -14,9 +16,8 @@
#define EFI_NOT_FOUND (-1)
#define EFI_NO_SMBIOS (-2)
-#include <Python.h>
-#include "catsprintf.h"
#include "global.h"
+#include "catsprintf.h"
extern void dmi_dump(struct dmi_header *h, const char *prefix);
extern void dmi_decode(struct dmi_header *h, u16 ver);
@@ -25,103 +26,11 @@ extern void to_dmi_header(struct dmi_header *h, u8 *data);
extern void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem);
extern int smbios_decode(u8 *buf, const char *devmem);
extern int legacy_decode(u8 *buf, const char *devmem);
+extern int submain(int argc, char * const argv[]);
-
-
-int main(int argc, char * const argv[])
-{
- bzero(buffer, 50000);
-
- int ret=0; /* Returned value */
- int found=0;
- size_t fp;
- int efi;
- u8 *buf;
-
- if(sizeof(u8)!=1 || sizeof(u16)!=2 || sizeof(u32)!=4 || '\0'!=0)
- {
- fprintf(stderr, "%s: compiler incompatibility\n", argv[0]);
- exit(255);
- }
-
- /* Set default option values */
- opt.devmem=DEFAULT_MEM_DEV;
- opt.flags=0;
-
- if(parse_command_line(argc, argv)<0)
- {
- ret=2;
- goto exit_free;
- }
-
- if(opt.flags & FLAG_HELP)
- {
- print_help();
- goto exit_free;
- }
-
- if(opt.flags & FLAG_VERSION)
- {
- printf("%s\n", VERSION);
- goto exit_free;
- }
-
- if(!(opt.flags & FLAG_QUIET))
- printf("# dmidecode %s\n", VERSION);
-
- /* First try EFI (ia64, Intel-based Mac) */
- efi=address_from_efi(&fp);
- switch(efi)
- {
- case EFI_NOT_FOUND:
- goto memory_scan;
- case EFI_NO_SMBIOS:
- ret=1;
- goto exit_free;
- }
-
- if((buf=mem_chunk(fp, 0x20, opt.devmem))==NULL)
- {
- ret=1;
- goto exit_free;
- }
-
- if(smbios_decode(buf, opt.devmem))
- found++;
- goto done;
-
-memory_scan:
- /* Fallback to memory scan (x86, x86_64) */
- if((buf=mem_chunk(0xF0000, 0x10000, opt.devmem))==NULL)
- {
- ret=1;
- goto exit_free;
- }
-
- for(fp=0; fp<=0xFFF0; fp+=16)
- {
- if(memcmp(buf+fp, "_SM_", 4)==0 && fp<=0xFFE0)
- {
- if(smbios_decode(buf+fp, opt.devmem))
- found++;
- fp+=16;
- }
- else if(memcmp(buf+fp, "_DMI_", 5)==0)
- {
- if (legacy_decode(buf+fp, opt.devmem))
- found++;
- }
- }
-
-done:
- free(buf);
-
- if(!found && !(opt.flags & FLAG_QUIET))
- printf("# No SMBIOS nor DMI entry point found, sorry.\n");
-
-exit_free:
- free(opt.type);
-
- printf("%s\n", buffer);
- return ret;
+int main(int argc, char * const argv[]) {
+ bzero(buffer, 50000);
+ int r = submain(argc, argv);
+ printf("%s", buffer);
+ return r;
}