summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--abrt.spec12
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/report-python/Makefile.am25
-rw-r--r--src/report-python/__init__.py1
-rw-r--r--src/report-python/crash_dump.c200
-rw-r--r--src/report-python/py_crash_dump.h30
-rw-r--r--src/report-python/pyreport_common.h22
-rw-r--r--src/report-python/reportmodule.c34
9 files changed, 327 insertions, 1 deletions
diff --git a/abrt.spec b/abrt.spec
index c1998cef..494b721e 100644
--- a/abrt.spec
+++ b/abrt.spec
@@ -77,6 +77,14 @@ Group: Development/Libraries
%description -n libreport-devel
Development libraries and headers for libreport.
+%package -n libreport-python
+Summary: Python bindings for report-libs.
+# Is group correct here? -
+Group: System Environment/Libraries
+
+%description -n libreport-python
+Python bindings for report-libs.
+
%package libs
Summary: Libraries for %{name}
Group: System Environment/Libraries
@@ -370,6 +378,10 @@ fi
%{_includedir}/report/*
%{_libdir}/libreport.so
+%files -n libreport-python
+%defattr(-,root,root,-)
+%{python_sitearch}/report/*
+
%files libs
%defattr(-,root,root,-)
%{_libdir}/libabrt*.so.*
diff --git a/configure.ac b/configure.ac
index d3d8a294..59e5d88a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,7 @@ PKG_CHECK_MODULES([LIBNOTIFY], [libnotify])
#PKG_CHECK_MODULES([NSS], [nss])
PKG_CHECK_MODULES([XMLRPC], [xmlrpc])
PKG_CHECK_MODULES([XMLRPC_CLIENT], [xmlrpc_client])
+PKG_CHECK_MODULES([PYTHON], [python])
PKG_PROG_PKG_CONFIG
AC_ARG_WITH([systemdsystemunitdir],
@@ -119,6 +120,7 @@ AC_CONFIG_FILES([
abrt.pc
src/include/Makefile
src/lib/Makefile
+ src/report-python/Makefile
src/plugins/Makefile
src/Makefile
src/btparser/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index fb4cba28..528a81c5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1 +1 @@
-SUBDIRS = include lib hooks btparser daemon applet gui cli plugins
+SUBDIRS = include lib report-python hooks btparser daemon applet gui cli plugins
diff --git a/src/report-python/Makefile.am b/src/report-python/Makefile.am
new file mode 100644
index 00000000..34ec090c
--- /dev/null
+++ b/src/report-python/Makefile.am
@@ -0,0 +1,25 @@
+pyreportexecdir = $(pyexecdir)/report
+
+pyreportexec_PYTHON = __init__.py
+
+pyreportexec_LTLIBRARIES = _pyreport.la
+
+_pyreport_la_SOURCES = \
+ reportmodule.c crash_dump.c py_crash_dump.h pyreport_common.h
+_pyreport_la_CPPFLAGS = \
+ -I$(srcdir)/../include/report -I$(srcdir)/../include \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
+ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \
+ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
+ -DLOCALSTATEDIR='"$(localstatedir)"' \
+ -DCONF_DIR=\"$(CONF_DIR)\" \
+ -DVAR_RUN=\"$(VAR_RUN)\" \
+ $(GLIB_CFLAGS) \
+ $(PYTHON_CFLAGS) \
+ -D_GNU_SOURCE
+_pyreport_la_LDFLAGS = \
+ -module \
+ -avoid-version \
+ -export-symbols-regex init_pyreport
+_pyreport_la_LIBADD = \
+ ../lib/libreport.la
diff --git a/src/report-python/__init__.py b/src/report-python/__init__.py
new file mode 100644
index 00000000..90109551
--- /dev/null
+++ b/src/report-python/__init__.py
@@ -0,0 +1 @@
+from _pyreport import *
diff --git a/src/report-python/crash_dump.c b/src/report-python/crash_dump.c
new file mode 100644
index 00000000..078e96bd
--- /dev/null
+++ b/src/report-python/crash_dump.c
@@ -0,0 +1,200 @@
+/*
+ Copyright (C) 2009 Abrt team.
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include <Python.h>
+#include <structmember.h>
+#include <errno.h>
+#include "crash_dump.h"
+#include "pyreport_common.h"
+
+typedef struct {
+ PyObject_HEAD
+ crash_data_t *cd;
+} p_crash_data;
+
+static void
+p_crash_data_dealloc(PyObject *pself)
+{
+ p_crash_data* self = (p_crash_data*)pself;
+ free_crash_data(self->cd);
+ self->cd = NULL;
+ self->ob_type->tp_free((PyObject*)self);
+}
+
+static PyObject *
+p_crash_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ p_crash_data *self;
+
+ self = (p_crash_data *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ self->cd = new_crash_data();
+
+ return (PyObject *)self;
+}
+
+static int
+p_crash_data_init(PyObject *pself, PyObject *args, PyObject *kwds)
+{
+ return 0;
+}
+
+/*
+void add_to_crash_data_ext(crash_data_t *crash_data,
+ const char *name,
+ const char *content,
+ unsigned flags);
+*/
+
+static PyObject * p_crash_data_add_ext(PyObject *pself, PyObject *args, PyObject *kwds)
+{
+ p_crash_data* self = (p_crash_data*)pself;
+
+
+ const char * name;
+ const char * content;
+ int FLAGS;
+ if(!PyArg_ParseTuple(args, "ssi", &name, &content, &FLAGS))
+ {
+ PyErr_SetString(ReportError, strerror(errno));
+ return NULL;
+ }
+ add_to_crash_data_ext(self->cd, name, content, FLAGS);
+
+ /* every function returns PyObject to return void we need to do this */
+ Py_RETURN_NONE;
+}
+static PyObject * p_crash_data_add(PyObject *pself, PyObject *args, PyObject *kwds)
+{
+ p_crash_data* self = (p_crash_data*)pself;
+
+
+ const char * name;
+ const char * content;
+ if(!PyArg_ParseTuple(args, "ss", &name, &content))
+ {
+ /* PyArg_ParseTuple raises the exception saying why it fails
+ * eg: TypeError: function takes exactly 2 arguments (1 given)
+ */
+ return NULL;
+ }
+ add_to_crash_data(self->cd, name, content);
+
+ /* every function returns PyObject to return void we need to do this */
+ Py_RETURN_NONE;
+}
+
+/*
+static inline struct crash_item *get_crash_data_item_or_NULL(crash_data_t *crash_data, const char *key)
+{
+ return (struct crash_item *)g_hash_table_lookup(crash_data, key);
+}
+*/
+
+static PyObject * p_get_crash_data_item(PyObject *pself, PyObject *args, PyObject *kwds)
+{
+ p_crash_data* self = (p_crash_data*)pself;
+
+ const char *key;
+ if(!PyArg_ParseTuple(args, "s", &key))
+ {
+ return NULL;
+ }
+ struct crash_item *ci = get_crash_data_item_or_NULL(self->cd, key);
+ return Py_BuildValue("sI", ci->content, ci->flags);
+}
+
+
+static PyObject * p_create_crash_dump_dir(PyObject *pself, PyObject *args)
+{
+ p_crash_data* self = (p_crash_data*)pself;
+ struct dump_dir *dd = create_crash_dump_dir(self->cd);
+ if(dd == NULL)
+ {
+ PyErr_SetString(ReportError, "Can't create the dump dir");
+ return NULL;
+ }
+ //FIXME: return a python representation of dump_dir, when we have it..
+ Py_RETURN_NONE;
+}
+
+static PyMemberDef p_crash_data_members[] = {
+ {NULL} /* Sentinel */
+};
+
+static PyMethodDef p_crash_data_methods[] = {
+ {"add", (PyCFunction)p_crash_data_add, METH_VARARGS,
+ "Adds item to the crash data using default flags"
+ },
+ {"add_ext", (PyCFunction)p_crash_data_add_ext, METH_VARARGS,
+ "Adds item to the crash data"
+ },
+ {"get", (PyCFunction)p_get_crash_data_item, METH_VARARGS,
+ "Gets the value of item indexed by the key"
+ },
+ {"to_dump_dir", (PyCFunction)p_create_crash_dump_dir, METH_NOARGS,
+ "Saves the crash_data to"LOCALSTATEDIR"/run/abrt/tmp-<pid>-<time>"
+ },
+ {NULL} /* Sentinel */
+};
+
+PyTypeObject p_crash_data_type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "report.p_crash_data", /*tp_name*/
+ sizeof(p_crash_data), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ p_crash_data_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "p_crash_data objects", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ p_crash_data_methods, /* tp_methods */
+ p_crash_data_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ p_crash_data_init, /* tp_init */
+ 0, /* tp_alloc */
+ p_crash_data_new, /* tp_new */
+};
+
+PyMethodDef module_methods[] = {
+ {NULL} /* Sentinel */
+};
diff --git a/src/report-python/py_crash_dump.h b/src/report-python/py_crash_dump.h
new file mode 100644
index 00000000..a188e522
--- /dev/null
+++ b/src/report-python/py_crash_dump.h
@@ -0,0 +1,30 @@
+/*
+ Copyright (C) 2009 Abrt team.
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <Python.h>
+
+void p_crash_data_dealloc(PyObject *pself);
+PyObject *p_crash_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
+int p_crash_data_init(PyObject *pself, PyObject *args, PyObject *kwds);
+PyObject *p_crash_data_add(PyObject *pself, PyObject *args, PyObject *kwds);
+
+/* crash_data object */
+extern PyTypeObject p_crash_data_type;
+/* crash_data methods */
+extern PyMethodDef module_methods[]; \ No newline at end of file
diff --git a/src/report-python/pyreport_common.h b/src/report-python/pyreport_common.h
new file mode 100644
index 00000000..c536827f
--- /dev/null
+++ b/src/report-python/pyreport_common.h
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2009 Abrt team.
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <Python.h>
+extern PyObject *ReportError;
+
diff --git a/src/report-python/reportmodule.c b/src/report-python/reportmodule.c
new file mode 100644
index 00000000..b73f88f5
--- /dev/null
+++ b/src/report-python/reportmodule.c
@@ -0,0 +1,34 @@
+#include <Python.h>
+#include "py_crash_dump.h"
+
+PyObject *ReportError;
+
+#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
+#define PyMODINIT_FUNC void
+#endif
+PyMODINIT_FUNC
+init_pyreport(void)
+{
+ PyObject* m;
+
+ if (PyType_Ready(&p_crash_data_type) < 0)
+ {
+ printf("PyType_Ready(&p_crash_data_type) < 0");
+ return;
+ }
+
+ m = Py_InitModule3("_pyreport", module_methods, "Python wrapper around crash_data_t");
+ if (m == NULL)
+ {
+ printf("m == NULL");
+ return;
+ }
+
+ /* init the exception object */
+ ReportError = PyErr_NewException("_pyreport.error", NULL, NULL);
+ Py_INCREF(ReportError);
+ PyModule_AddObject(m, "error", ReportError);
+
+ Py_INCREF(&p_crash_data_type);
+ PyModule_AddObject(m, "crash_data", (PyObject *)&p_crash_data_type);
+}