diff options
author | David Sommerseth <davids@redhat.com> | 2009-04-30 19:38:25 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2009-04-30 19:38:25 +0200 |
commit | 1bf1da9fa4ad24148fe18c1c5baa9a4ec931402c (patch) | |
tree | 3289359e9460924b03c460099c6f277d6594bb05 | |
parent | 89d2c50a648e3affd81ceb24e332bbd60de2b75d (diff) | |
download | python-dmidecode-1bf1da9fa4ad24148fe18c1c5baa9a4ec931402c.tar.gz python-dmidecode-1bf1da9fa4ad24148fe18c1c5baa9a4ec931402c.tar.xz python-dmidecode-1bf1da9fa4ad24148fe18c1c5baa9a4ec931402c.zip |
Improved setting of pythonmap.xml
The default file is now set to /usr/share/python-dmidecode/pythonmap.xml
(defined in config.h) and can be overridden with the dmidecode.pythonmap()
function in Python.
-rw-r--r-- | src/config.h | 4 | ||||
-rw-r--r-- | src/dmidecodemodule.c | 27 | ||||
-rw-r--r-- | src/dmihelper.h | 1 |
3 files changed, 31 insertions, 1 deletions
diff --git a/src/config.h b/src/config.h index 713ac5d..f4c0fc4 100644 --- a/src/config.h +++ b/src/config.h @@ -23,4 +23,8 @@ #define ALIGNMENT_WORKAROUND #endif +#ifndef PYTHON_XML_MAP +#define PYTHON_XML_MAP "/usr/share/python-dmidecode/pythonmap.xmp" +#endif + #endif diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c index 05689b0..fc3a7ed 100644 --- a/src/dmidecodemodule.c +++ b/src/dmidecodemodule.c @@ -21,6 +21,7 @@ static void init(void) opt.type = NULL; opt.mappingxml = NULL; opt.dmiversion_n = NULL; + opt.python_xml_map = strdup(PYTHON_XML_MAP); } u8 *parse_opt_type(u8 * p, const char *arg) @@ -250,7 +251,7 @@ static PyObject *dmidecode_get(PyObject *self, const char *section) // Convert the retrieved XML nodes to Python dicts if( opt.mappingxml == NULL ) { // Load mapping into memory - opt.mappingxml = xmlReadFile("pythonmap.xml", NULL, 0); + opt.mappingxml = xmlReadFile(opt.python_xml_map, NULL, 0); assert( opt.mappingxml != NULL ); } @@ -387,6 +388,27 @@ static PyObject *dmidecode_set_dev(PyObject * self, PyObject * arg) //PyErr_Occurred(); } +static PyObject *dmidecode_set_pythonxmlmap(PyObject * self, PyObject * arg) +{ + if(PyString_Check(arg)) { + struct stat fileinfo; + char *fname = PyString_AsString(arg); + + memset(&fileinfo, 0, sizeof(struct stat)); + + if( stat(fname, &fileinfo) != 0 ) { + PyErr_SetString(PyExc_IOError, "Could not access the given python map XML file"); + return NULL; + } + + free(opt.python_xml_map); + opt.python_xml_map = strdup(fname); + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } +} + static PyMethodDef DMIDataMethods[] = { {(char *)"dump", dmidecode_dump, METH_NOARGS, (char *)"Dump dmidata to set file"}, @@ -407,6 +429,9 @@ static PyMethodDef DMIDataMethods[] = { {(char *)"type", dmidecode_get_type, METH_VARARGS, (char *)"By Type"}, + {(char *)"pythonmap", dmidecode_set_pythonxmlmap, METH_O, + (char *) "Use another python dict map definition. The default file is " PYTHON_XML_MAP}, + {NULL, NULL, 0, NULL} }; diff --git a/src/dmihelper.h b/src/dmihelper.h index 50cb185..33da699 100644 --- a/src/dmihelper.h +++ b/src/dmihelper.h @@ -115,6 +115,7 @@ typedef struct _options { xmlDoc *mappingxml; xmlNode *dmiversion_n; PyObject *dumpfile; + char *python_xml_map; } options; extern options opt; |