summaryrefslogtreecommitdiffstats
path: root/src/dmidecodemodule.c
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2009-04-30 19:38:25 +0200
committerDavid Sommerseth <davids@redhat.com>2009-04-30 19:38:25 +0200
commit1bf1da9fa4ad24148fe18c1c5baa9a4ec931402c (patch)
tree3289359e9460924b03c460099c6f277d6594bb05 /src/dmidecodemodule.c
parent89d2c50a648e3affd81ceb24e332bbd60de2b75d (diff)
downloadpython-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.
Diffstat (limited to 'src/dmidecodemodule.c')
-rw-r--r--src/dmidecodemodule.c27
1 files changed, 26 insertions, 1 deletions
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}
};