diff --git a/src/report-python/Makefile.am b/src/report-python/Makefile.am index c1b3759..60b231a 100644 --- a/src/report-python/Makefile.am +++ b/src/report-python/Makefile.am @@ -12,6 +12,7 @@ _pyreport_la_SOURCES = \ dump_dir.c \ run_event.c \ report.c \ + client.c \ common.h _pyreport_la_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ diff --git a/src/report-python/client.c b/src/report-python/client.c index e69de29..7177ae3 100644 --- a/src/report-python/client.c +++ b/src/report-python/client.c @@ -0,0 +1,83 @@ +/* + 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 "common.h" + +/* C: void alert(const char *message); */ +PyObject *p_alert(PyObject *pself, PyObject *args) +{ + const char *message; + if (!PyArg_ParseTuple(args, "s", &message)) + { + return NULL; + } + alert(message); + Py_RETURN_NONE; +} + +/* C: char *ask(const char *question, char *response, int response_len); */ +PyObject *p_ask(PyObject *pself, PyObject *args) +{ + const char *question; + if (!PyArg_ParseTuple(args, "s", &question)) + { + return NULL; + } + + char response[256]; + if (!ask(question, response, sizeof(response))) + { + Py_RETURN_NONE; + } + + return Py_BuildValue("s", response); +} + +/* C: char *ask_password(const char *question, char *response, int response_len); */ +PyObject *p_ask_password(PyObject *pself, PyObject *args) +{ + const char *question; + if (!PyArg_ParseTuple(args, "s", &question)) + { + return NULL; + } + + char response[256]; + if (!ask_password(question, response, sizeof(response))) + { + Py_RETURN_NONE; + } + + return Py_BuildValue("s", response); +} + +/* C: int ask_yes_no(const char *question); */ +PyObject *p_ask_yes_no(PyObject *pself, PyObject *args) +{ + const char *question; + if (!PyArg_ParseTuple(args, "s", &question)) + { + return NULL; + } + + int response = ask_yes_no(question); + + return Py_BuildValue("i", response); +} diff --git a/src/report-python/common.h b/src/report-python/common.h index 713aa2f..48cf7e0 100644 --- a/src/report-python/common.h +++ b/src/report-python/common.h @@ -18,6 +18,7 @@ */ #include +#include "client.h" #include "dump_dir.h" #include "problem_data.h" #include "run_event.h" @@ -51,3 +52,8 @@ PyObject *p_delete_dump_dir(PyObject *pself, PyObject *args); PyObject *p_report_problem_in_dir(PyObject *pself, PyObject *args); PyObject *p_report_problem_in_memory(PyObject *pself, PyObject *args); PyObject *p_report_problem(PyObject *pself, PyObject *args); +/* for include/client.h */ +PyObject *p_alert(PyObject *pself, PyObject *args); +PyObject *p_ask(PyObject *pself, PyObject *args); +PyObject *p_ask_password(PyObject *pself, PyObject *args); +PyObject *p_ask_yes_no(PyObject *pself, PyObject *args); diff --git a/src/report-python/reportmodule.c b/src/report-python/reportmodule.c index 3d802f9..942d9d6 100644 --- a/src/report-python/reportmodule.c +++ b/src/report-python/reportmodule.c @@ -32,6 +32,11 @@ static PyMethodDef module_methods[] = { { "report_problem_in_dir" , p_report_problem_in_dir , METH_VARARGS }, { "report_problem_in_memory" , p_report_problem_in_memory, METH_VARARGS }, { "report_problem" , p_report_problem , METH_VARARGS }, + /* for include/client.h */ + { "alert" , p_alert , METH_VARARGS }, + { "ask" , p_ask , METH_VARARGS }, + { "ask_password" , p_ask_password , METH_VARARGS }, + { "ask_yes_no" , p_ask_yes_no , METH_VARARGS }, { NULL } };