summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-12-15 18:33:43 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2010-12-15 18:33:43 +0100
commit6da0fdade325c2ce0f371e661801e6beb1e70cdb (patch)
tree7e3d359498fcb1119f19fb34dbae923f19317083
parent544804d5e19cd8890c069273bd93801689e6f8e7 (diff)
downloadabrt-6da0fdade325c2ce0f371e661801e6beb1e70cdb.tar.gz
abrt-6da0fdade325c2ce0f371e661801e6beb1e70cdb.tar.xz
abrt-6da0fdade325c2ce0f371e661801e6beb1e70cdb.zip
python wrappers: make crash_data.create_crash_dump_dir() work
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--src/report-python/common.h10
-rw-r--r--src/report-python/crash_dump.c14
-rw-r--r--src/report-python/dump_dir.c47
-rw-r--r--src/report-python/reportmodule.c15
-rw-r--r--src/report-python/test_crash_data22
-rw-r--r--src/report-python/test_dd_create20
6 files changed, 109 insertions, 19 deletions
diff --git a/src/report-python/common.h b/src/report-python/common.h
index b0a384c0..f0e8727a 100644
--- a/src/report-python/common.h
+++ b/src/report-python/common.h
@@ -24,3 +24,13 @@ extern PyObject *ReportError;
/* type objects */
extern PyTypeObject p_crash_data_type;
extern PyTypeObject p_dump_dir_type;
+
+/* module-level functions */
+PyObject *p_dd_opendir(PyObject *module, PyObject *args);
+PyObject *p_dd_create(PyObject *module, PyObject *args);
+
+/* python objects' struct defs */
+typedef struct {
+ PyObject_HEAD
+ struct dump_dir *dd;
+} p_dump_dir;
diff --git a/src/report-python/crash_dump.c b/src/report-python/crash_dump.c
index c56db087..868e97ec 100644
--- a/src/report-python/crash_dump.c
+++ b/src/report-python/crash_dump.c
@@ -108,18 +108,22 @@ static PyObject *p_get_crash_data_item(PyObject *pself, PyObject *args)
return Py_BuildValue("sI", ci->content, ci->flags);
}
+/* struct dump_dir *create_crash_dump_dir(crash_data_t *crash_data); */
static PyObject *p_create_crash_dump_dir(PyObject *pself, PyObject *args)
{
p_crash_data *self = (p_crash_data*)pself;
+ p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type);
+ if (!new_dd)
+ return NULL;
struct dump_dir *dd = create_crash_dump_dir(self->cd);
- if (dd == NULL)
+ if (!dd)
{
+ PyObject_Del((PyObject*)new_dd);
PyErr_SetString(ReportError, "Can't create the dump dir");
return NULL;
}
- //FIXME: return a python representation of dump_dir, when we have it..
- dd_close(dd);
- Py_RETURN_NONE;
+ new_dd->dd = dd;
+ return (PyObject*)new_dd;
}
//static PyMemberDef p_crash_data_members[] = {
@@ -130,7 +134,7 @@ static PyMethodDef p_crash_data_methods[] = {
{ "add" , p_crash_data_add, METH_VARARGS, "Adds item to the crash data using default flags" },
{ "add_ext" , p_crash_data_add_ext, METH_VARARGS, "Adds item to the crash data" },
{ "get" , p_get_crash_data_item, METH_VARARGS, "Gets the value of item indexed by the key" },
- { "to_dump_dir", p_create_crash_dump_dir, METH_NOARGS, "Saves the crash_data to"LOCALSTATEDIR"/run/abrt/tmp-<pid>-<time>" },
+ { "create_crash_dump_dir", p_create_crash_dump_dir, METH_NOARGS, "Saves the crash_data to"LOCALSTATEDIR"/run/abrt/tmp-<pid>-<time>" },
{ NULL }
};
diff --git a/src/report-python/dump_dir.c b/src/report-python/dump_dir.c
index 71daa088..8e1f17ef 100644
--- a/src/report-python/dump_dir.c
+++ b/src/report-python/dump_dir.c
@@ -26,11 +26,6 @@
#include "dump_dir.h"
#include "common.h"
-typedef struct {
- PyObject_HEAD
- struct dump_dir *dd;
-} p_dump_dir;
-
static void
p_dump_dir_dealloc(PyObject *pself)
{
@@ -147,6 +142,16 @@ static PyMethodDef p_dump_dir_methods[] = {
{ NULL }
};
+static int p_dd_is_non_null(PyObject *pself)
+{
+ p_dump_dir *self = (p_dump_dir*)pself;
+ return self->dd != NULL;
+}
+
+static PyNumberMethods p_dump_dir_number_methods = {
+ .nb_nonzero = p_dd_is_non_null,
+};
+
PyTypeObject p_dump_dir_type = {
PyObject_HEAD_INIT(NULL)
.tp_name = "report.dump_dir",
@@ -158,13 +163,41 @@ PyTypeObject p_dump_dir_type = {
//.tp_members = p_dump_dir_members,
//.tp_init = p_dump_dir_init,
.tp_new = p_dump_dir_new,
+ .tp_as_number = &p_dump_dir_number_methods,
};
/* struct dump_dir *dd_opendir(const char *dir, int flags); */
-//static PyObject *p_dd_opendir(PyObject *pself, PyObject *args);
+PyObject *p_dd_opendir(PyObject *module, PyObject *args)
+{
+ const char *dir;
+ int flags = 0;
+ if (!PyArg_ParseTuple(args, "s|i", &dir, &flags))
+ return NULL;
+// PyObject *new_obj = PyObject_CallObject(&p_dump_dir_type, NULL); /* constructor call */
+// p_dump_dir *new_dd = (p_dump_dir*)new_obj;
+ p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type);
+ if (!new_dd)
+ return NULL;
+ new_dd->dd = dd_opendir(dir, flags);
+ return (PyObject*)new_dd;
+}
+
/* struct dump_dir *dd_create(const char *dir, uid_t uid); */
-//static PyObject *p_dd_create(PyObject *pself, PyObject *args);
+PyObject *p_dd_create(PyObject *module, PyObject *args)
+{
+ const char *dir;
+ int uid;
+ if (!PyArg_ParseTuple(args, "si", &dir, &uid))
+ return NULL;
+// PyObject *new_obj = PyObject_CallObject(&p_dump_dir_type, NULL); /* constructor call */
+// p_dump_dir *new_dd = (p_dump_dir*)new_obj;
+ p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type);
+ if (!new_dd)
+ return NULL;
+ new_dd->dd = dd_create(dir, uid);
+ return (PyObject*)new_dd;
+}
/* void delete_crash_dump_dir(const char *dd_dir); */
//static PyObject *p_delete_crash_dump_dir(PyObject *pself, PyObject *args);
diff --git a/src/report-python/reportmodule.c b/src/report-python/reportmodule.c
index f98ba75e..5fa31ca2 100644
--- a/src/report-python/reportmodule.c
+++ b/src/report-python/reportmodule.c
@@ -21,12 +21,12 @@
PyObject *ReportError;
-//static PyMethodDef module_methods[] = {
-// { "dd_opendir" , p_dd_opendir, METH_VARARGS, NULL };
-// { "dd_create" , p_dd_create, METH_VARARGS, NULL };
+static PyMethodDef module_methods[] = {
+ { "dd_opendir" , p_dd_opendir, METH_VARARGS, NULL },
+ { "dd_create" , p_dd_create, METH_VARARGS, NULL },
// { "delete_crash_dump_dir", p_delete_crash_dump_dir, METH_VARARGS, NULL },
-// { NULL }
-//};
+ { NULL }
+};
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
@@ -47,8 +47,9 @@ init_pyreport(void)
return;
}
- m = Py_InitModule3("_pyreport", /*module_methods:*/ NULL, "Python wrapper for libreport");
- if (m == NULL)
+ m = Py_InitModule("_pyreport", module_methods);
+ //m = Py_InitModule3("_pyreport", module_methods, "Python wrapper for libreport");
+ if (!m)
{
printf("m == NULL\n");
return;
diff --git a/src/report-python/test_crash_data b/src/report-python/test_crash_data
new file mode 100644
index 00000000..50afc002
--- /dev/null
+++ b/src/report-python/test_crash_data
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+
+from report import *
+import report
+
+cd = crash_data()
+cd.add("foo", "bar")
+
+dd = cd.create_crash_dump_dir()
+
+if dd:
+ print "dd is nonzero"
+else:
+ print "dd is zero"
+
+print "closing"
+dd.close()
+
+if dd:
+ print "dd is nonzero"
+else:
+ print "dd is zero"
diff --git a/src/report-python/test_dd_create b/src/report-python/test_dd_create
new file mode 100644
index 00000000..0290482f
--- /dev/null
+++ b/src/report-python/test_dd_create
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+from report import *
+import report
+
+dd = dd_create("testdir", 0)
+print dd
+
+if dd:
+ print "dd is nonzero"
+else:
+ print "dd is zero"
+
+print "closing"
+dd.close()
+
+if dd:
+ print "dd is nonzero"
+else:
+ print "dd is zero"