From 042d62126a0ca8b6b9d2fb4d417f07691be90536 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 23 Apr 2011 17:21:17 +0200 Subject: mass replace of crash_data with problem_data Signed-off-by: Denys Vlasenko --- src/report-python/Makefile.am | 2 +- src/report-python/__init__.py | 4 +- src/report-python/common.h | 8 +- src/report-python/crash_data.c | 137 ------------------------- src/report-python/dump_dir.c | 2 +- src/report-python/problem_data.c | 137 +++++++++++++++++++++++++ src/report-python/reportmodule.c | 8 +- src/report-python/run_event.c | 14 +-- src/report-python/test_crash_data | 21 ---- src/report-python/test_crash_data2 | 10 -- src/report-python/test_full | 6 +- src/report-python/test_full2 | 4 +- src/report-python/test_problem_data | 21 ++++ src/report-python/test_problem_data2 | 10 ++ src/report-python/test_setroubleshoot_example2 | 2 +- 15 files changed, 193 insertions(+), 193 deletions(-) delete mode 100644 src/report-python/crash_data.c create mode 100644 src/report-python/problem_data.c delete mode 100755 src/report-python/test_crash_data delete mode 100755 src/report-python/test_crash_data2 create mode 100644 src/report-python/test_problem_data create mode 100644 src/report-python/test_problem_data2 (limited to 'src/report-python') diff --git a/src/report-python/Makefile.am b/src/report-python/Makefile.am index 94dc3abb..c7b2dd67 100644 --- a/src/report-python/Makefile.am +++ b/src/report-python/Makefile.am @@ -8,7 +8,7 @@ pyreportexec_LTLIBRARIES = _pyreport.la _pyreport_la_SOURCES = \ reportmodule.c \ - crash_data.c \ + problem_data.c \ dump_dir.c \ run_event.c \ common.h diff --git a/src/report-python/__init__.py b/src/report-python/__init__.py index 0b0f5685..1e87dc47 100644 --- a/src/report-python/__init__.py +++ b/src/report-python/__init__.py @@ -108,7 +108,7 @@ def createAlertSignature(component, hashmarkername, hashvalue, summary, alertSig #### return version return _hardcoded_default_version - cd = crash_data() + cd = problem_data() cd.add("component", component) cd.add("hashmarkername", hashmarkername) cd.add("localhash", hashvalue) @@ -126,5 +126,5 @@ def report(cd, io_unused): ### Silmpler alternative: state = run_event_state() #state.logging_callback = logfunc - r = state.run_event_on_crash_data(cd, "report") + r = state.run_event_on_problem_data(cd, "report") return r diff --git a/src/report-python/common.h b/src/report-python/common.h index d6d209e9..c94e8d90 100644 --- a/src/report-python/common.h +++ b/src/report-python/common.h @@ -19,14 +19,14 @@ #include #include "dump_dir.h" -#include "crash_data.h" +#include "problem_data.h" #include "run_event.h" /* exception object */ extern PyObject *ReportError; /* type objects */ -extern PyTypeObject p_crash_data_type; +extern PyTypeObject p_problem_data_type; extern PyTypeObject p_dump_dir_type; extern PyTypeObject p_run_event_state_type; @@ -43,5 +43,5 @@ typedef struct { typedef struct { PyObject_HEAD - crash_data_t *cd; -} p_crash_data; + problem_data_t *cd; +} p_problem_data; diff --git a/src/report-python/crash_data.c b/src/report-python/crash_data.c deleted file mode 100644 index 217560e5..00000000 --- a/src/report-python/crash_data.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - Copyright (C) 2010 Abrt team. - Copyright (C) 2010 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 -#include - -#include -#include "common.h" - -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(pself); -} - -static PyObject * -p_crash_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - p_crash_data *self = (p_crash_data *)type->tp_alloc(type, 0); - if (self) - 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(PyObject *pself, PyObject *args) -{ - p_crash_data *self = (p_crash_data*)pself; - - const char *name; - const char *content; - int flags = 0; - if (!PyArg_ParseTuple(args, "ss|i", &name, &content, &flags)) - { - /* PyArg_ParseTuple raises the exception saying why it fails - * eg: TypeError: function takes exactly 2 arguments (1 given) - */ - 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; -} - -/* struct crash_item *get_crash_data_item_or_NULL(crash_data_t *crash_data, const char *key); */ -static PyObject *p_get_crash_data_item(PyObject *pself, PyObject *args) -{ - 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); - if (ci == NULL) - { - Py_RETURN_NONE; - } - return Py_BuildValue("sI", ci->content, ci->flags); -} - -/* struct dump_dir *create_dump_dir_from_crash_data(crash_data_t *crash_data, const char *base_dir_name); */ -static PyObject *p_create_dump_dir_from_crash_data(PyObject *pself, PyObject *args) -{ - p_crash_data *self = (p_crash_data*)pself; - const char *base_dir_name = NULL; - if (!PyArg_ParseTuple(args, "|s", &base_dir_name)) - { - return NULL; - } - p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type); - if (!new_dd) - return NULL; - struct dump_dir *dd = create_dump_dir_from_crash_data(self->cd, base_dir_name); - if (!dd) - { - PyObject_Del((PyObject*)new_dd); - PyErr_SetString(ReportError, "Can't create the dump dir"); - return NULL; - } - new_dd->dd = dd; - return (PyObject*)new_dd; -} - -//static PyMemberDef p_crash_data_members[] = { -// { NULL } -//}; - -static PyMethodDef p_crash_data_methods[] = { - /* method_name, func, flags, doc_string */ - { "add" , p_crash_data_add , METH_VARARGS }, - { "get" , p_get_crash_data_item , METH_VARARGS }, - { "create_dump_dir", p_create_dump_dir_from_crash_data, METH_VARARGS }, - { NULL } -}; - -PyTypeObject p_crash_data_type = { - PyObject_HEAD_INIT(NULL) - .tp_name = "report.crash_data", - .tp_basicsize = sizeof(p_crash_data), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_new = p_crash_data_new, - .tp_dealloc = p_crash_data_dealloc, - //.tp_init = p_crash_data_init, - //.tp_members = p_crash_data_members, - .tp_methods = p_crash_data_methods, -}; diff --git a/src/report-python/dump_dir.c b/src/report-python/dump_dir.c index c34cc869..e14e68d2 100644 --- a/src/report-python/dump_dir.c +++ b/src/report-python/dump_dir.c @@ -1,5 +1,5 @@ /* - On-disk storage of crash dumps + On-disk storage of problem data Copyright (C) 2010 Abrt team Copyright (C) 2010 RedHat inc. diff --git a/src/report-python/problem_data.c b/src/report-python/problem_data.c new file mode 100644 index 00000000..ac80362a --- /dev/null +++ b/src/report-python/problem_data.c @@ -0,0 +1,137 @@ +/* + Copyright (C) 2010 Abrt team. + Copyright (C) 2010 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 +#include + +#include +#include "common.h" + +static void +p_problem_data_dealloc(PyObject *pself) +{ + p_problem_data *self = (p_problem_data*)pself; + free_problem_data(self->cd); + self->cd = NULL; + self->ob_type->tp_free(pself); +} + +static PyObject * +p_problem_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + p_problem_data *self = (p_problem_data *)type->tp_alloc(type, 0); + if (self) + self->cd = new_problem_data(); + return (PyObject *)self; +} + +//static int +//p_problem_data_init(PyObject *pself, PyObject *args, PyObject *kwds) +//{ +// return 0; +//} + +/* +void add_to_problem_data_ext(problem_data_t *problem_data, + const char *name, + const char *content, + unsigned flags); +*/ +static PyObject *p_problem_data_add(PyObject *pself, PyObject *args) +{ + p_problem_data *self = (p_problem_data*)pself; + + const char *name; + const char *content; + int flags = 0; + if (!PyArg_ParseTuple(args, "ss|i", &name, &content, &flags)) + { + /* PyArg_ParseTuple raises the exception saying why it fails + * eg: TypeError: function takes exactly 2 arguments (1 given) + */ + return NULL; + } + add_to_problem_data_ext(self->cd, name, content, flags); + + /* every function returns PyObject, to return void we need to do this */ + Py_RETURN_NONE; +} + +/* struct problem_item *get_problem_data_item_or_NULL(problem_data_t *problem_data, const char *key); */ +static PyObject *p_get_problem_data_item(PyObject *pself, PyObject *args) +{ + p_problem_data *self = (p_problem_data*)pself; + const char *key; + if (!PyArg_ParseTuple(args, "s", &key)) + { + return NULL; + } + struct problem_item *ci = get_problem_data_item_or_NULL(self->cd, key); + if (ci == NULL) + { + Py_RETURN_NONE; + } + return Py_BuildValue("sI", ci->content, ci->flags); +} + +/* struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name); */ +static PyObject *p_create_dump_dir_from_problem_data(PyObject *pself, PyObject *args) +{ + p_problem_data *self = (p_problem_data*)pself; + const char *base_dir_name = NULL; + if (!PyArg_ParseTuple(args, "|s", &base_dir_name)) + { + return NULL; + } + p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type); + if (!new_dd) + return NULL; + struct dump_dir *dd = create_dump_dir_from_problem_data(self->cd, base_dir_name); + if (!dd) + { + PyObject_Del((PyObject*)new_dd); + PyErr_SetString(ReportError, "Can't create the dump dir"); + return NULL; + } + new_dd->dd = dd; + return (PyObject*)new_dd; +} + +//static PyMemberDef p_problem_data_members[] = { +// { NULL } +//}; + +static PyMethodDef p_problem_data_methods[] = { + /* method_name, func, flags, doc_string */ + { "add" , p_problem_data_add , METH_VARARGS }, + { "get" , p_get_problem_data_item , METH_VARARGS }, + { "create_dump_dir", p_create_dump_dir_from_problem_data, METH_VARARGS }, + { NULL } +}; + +PyTypeObject p_problem_data_type = { + PyObject_HEAD_INIT(NULL) + .tp_name = "report.problem_data", + .tp_basicsize = sizeof(p_problem_data), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_new = p_problem_data_new, + .tp_dealloc = p_problem_data_dealloc, + //.tp_init = p_problem_data_init, + //.tp_members = p_problem_data_members, + .tp_methods = p_problem_data_methods, +}; diff --git a/src/report-python/reportmodule.c b/src/report-python/reportmodule.c index a684984e..c40cfaf6 100644 --- a/src/report-python/reportmodule.c +++ b/src/report-python/reportmodule.c @@ -36,9 +36,9 @@ static PyMethodDef module_methods[] = { PyMODINIT_FUNC init_pyreport(void) { - if (PyType_Ready(&p_crash_data_type) < 0) + if (PyType_Ready(&p_problem_data_type) < 0) { - printf("PyType_Ready(&p_crash_data_type) < 0\n"); + printf("PyType_Ready(&p_problem_data_type) < 0\n"); return; } if (PyType_Ready(&p_dump_dir_type) < 0) @@ -66,8 +66,8 @@ init_pyreport(void) PyModule_AddObject(m, "error", ReportError); /* init type objects */ - Py_INCREF(&p_crash_data_type); - PyModule_AddObject(m, "crash_data", (PyObject *)&p_crash_data_type); + Py_INCREF(&p_problem_data_type); + PyModule_AddObject(m, "problem_data", (PyObject *)&p_problem_data_type); PyModule_AddObject(m, "CD_FLAG_BIN" , Py_BuildValue("i", CD_FLAG_BIN )); PyModule_AddObject(m, "CD_FLAG_TXT" , Py_BuildValue("i", CD_FLAG_TXT )); PyModule_AddObject(m, "CD_FLAG_ISEDITABLE" , Py_BuildValue("i", CD_FLAG_ISEDITABLE )); diff --git a/src/report-python/run_event.c b/src/report-python/run_event.c index 684c7fc7..50e3794e 100644 --- a/src/report-python/run_event.c +++ b/src/report-python/run_event.c @@ -21,7 +21,7 @@ #include #include "common.h" -#include "crash_data.h" +#include "problem_data.h" #include "run_event.h" typedef struct { @@ -110,17 +110,17 @@ static PyObject *p_run_event_on_dir_name(PyObject *pself, PyObject *args) return obj; } -/* int run_event_on_crash_data(struct run_event_state *state, crash_data_t *data, const char *event); */ -static PyObject *p_run_event_on_crash_data(PyObject *pself, PyObject *args) +/* int run_event_on_problem_data(struct run_event_state *state, problem_data_t *data, const char *event); */ +static PyObject *p_run_event_on_problem_data(PyObject *pself, PyObject *args) { p_run_event_state *self = (p_run_event_state*)pself; - p_crash_data *cd; + p_problem_data *cd; const char *event; - if (!PyArg_ParseTuple(args, "O!s", &p_crash_data_type, &cd, &event)) + if (!PyArg_ParseTuple(args, "O!s", &p_problem_data_type, &cd, &event)) { return NULL; } - int r = run_event_on_crash_data(self->state, cd->cd, event); + int r = run_event_on_problem_data(self->state, cd->cd, event); PyObject *obj = Py_BuildValue("i", r); return obj; } @@ -194,7 +194,7 @@ static int set_logging_callback(PyObject *pself, PyObject *callback, void *unuse static PyMethodDef p_run_event_state_methods[] = { /* method_name, func, flags, doc_string */ { "run_event_on_dir_name" , p_run_event_on_dir_name , METH_VARARGS }, - { "run_event_on_crash_data", p_run_event_on_crash_data, METH_VARARGS }, + { "run_event_on_problem_data", p_run_event_on_problem_data, METH_VARARGS }, { NULL } }; diff --git a/src/report-python/test_crash_data b/src/report-python/test_crash_data deleted file mode 100755 index 6f719a8f..00000000 --- a/src/report-python/test_crash_data +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python - -from report import * - -cd = crash_data() -cd.add("foo", "bar") - -dd = cd.create_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_crash_data2 b/src/report-python/test_crash_data2 deleted file mode 100755 index 2594f863..00000000 --- a/src/report-python/test_crash_data2 +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/python - -from report import * - -cd = crash_data() -cd.add("foo", "bar") - -print "foo:", cd.get("foo") -print "nonexistent:", cd.get("nonexistent") -print "done" diff --git a/src/report-python/test_full b/src/report-python/test_full index 103535dd..107c4857 100755 --- a/src/report-python/test_full +++ b/src/report-python/test_full @@ -3,7 +3,7 @@ import sys from report import * -def run_event_on_crash_data(cd, event, log_function = None): +def run_event_on_problem_data(cd, event, log_function = None): dd = cd.create_dump_dir("/tmp") dir_name = dd.name print "Created dump_dir:", dir_name @@ -20,8 +20,8 @@ def run_event_on_crash_data(cd, event, log_function = None): def log_function(line): print "LOG:", line -cd = crash_data() +cd = problem_data() cd.add("foo", "bar") cd.add("analyzer", "baz", CD_FLAG_ISNOTEDITABLE) -r = run_event_on_crash_data(cd, "post-create", log_function) +r = run_event_on_problem_data(cd, "post-create", log_function) print "Result:", r diff --git a/src/report-python/test_full2 b/src/report-python/test_full2 index 734946eb..e6cfd4d9 100755 --- a/src/report-python/test_full2 +++ b/src/report-python/test_full2 @@ -6,12 +6,12 @@ from report import * def log_function(line): print "LOG:", line -cd = crash_data() +cd = problem_data() cd.add("foo", "bar") cd.add("analyzer", "baz", CD_FLAG_ISNOTEDITABLE) st = run_event_state() st.logging_callback = log_function -r = st.run_event_on_crash_data(cd, "post-create") +r = st.run_event_on_problem_data(cd, "post-create") print "Result:", r diff --git a/src/report-python/test_problem_data b/src/report-python/test_problem_data new file mode 100644 index 00000000..16f1f9ae --- /dev/null +++ b/src/report-python/test_problem_data @@ -0,0 +1,21 @@ +#!/usr/bin/python + +from report import * + +cd = problem_data() +cd.add("foo", "bar") + +dd = cd.create_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_problem_data2 b/src/report-python/test_problem_data2 new file mode 100644 index 00000000..3d3692b9 --- /dev/null +++ b/src/report-python/test_problem_data2 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +from report import * + +cd = problem_data() +cd.add("foo", "bar") + +print "foo:", cd.get("foo") +print "nonexistent:", cd.get("nonexistent") +print "done" diff --git a/src/report-python/test_setroubleshoot_example2 b/src/report-python/test_setroubleshoot_example2 index 8aebcdfe..b712cda7 100755 --- a/src/report-python/test_setroubleshoot_example2 +++ b/src/report-python/test_setroubleshoot_example2 @@ -22,6 +22,6 @@ def logging_callback(line): return state = report.run_event_state() state.logging_callback = logging_callback -rc = state.run_event_on_crash_data(signature, "report") +rc = state.run_event_on_problem_data(signature, "report") print "rc:", rc -- cgit