diff --git a/configure.ac b/configure.ac index 61f16ae..4b01af6 100644 --- a/configure.ac +++ b/configure.ac @@ -126,6 +126,7 @@ AC_CONFIG_FILES([ src/cli/Makefile src/report-newt/Makefile src/plugins/Makefile + src/client-python/Makefile po/Makefile.in ]) diff --git a/libreport.spec.in b/libreport.spec.in index c50209f..9d74e9d 100644 --- a/libreport.spec.in +++ b/libreport.spec.in @@ -258,6 +258,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %files python %defattr(-,root,root,-) %{python_sitearch}/report/* +%{python_sitearch}/reportclient/* %files cli %defattr(-,root,root,-) diff --git a/src/Makefile.am b/src/Makefile.am index 24dfeb2..3a6da3f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1 +1 @@ -SUBDIRS = include lib plugins report-python gtk-helpers gui-wizard-gtk cli report-newt +SUBDIRS = include lib plugins report-python gtk-helpers gui-wizard-gtk cli report-newt client-python diff --git a/src/client-python/Makefile.am b/src/client-python/Makefile.am index e69de29..5a2a58f 100644 --- a/src/client-python/Makefile.am +++ b/src/client-python/Makefile.am @@ -0,0 +1,29 @@ +clientexecdir = $(pyexecdir)/reportclient + +clientexec_PYTHON = \ + __init__.py + +clientexec_LTLIBRARIES = _reportclient.la + +_reportclient_la_SOURCES = \ + clientmodule.c \ + client.c \ + common.h +_reportclient_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 \ + -Wall -Wwrite-strings -Werror +_reportclient_la_LDFLAGS = \ + -module \ + -avoid-version \ + -export-symbols-regex init_reportclient +_reportclient_la_LIBADD = \ + ../lib/libreport.la diff --git a/src/client-python/__init__.py b/src/client-python/__init__.py index e69de29..6114b5a 100644 --- a/src/client-python/__init__.py +++ b/src/client-python/__init__.py @@ -0,0 +1,15 @@ +# 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. + +from _reportclient import * diff --git a/src/client-python/client.c b/src/client-python/client.c index e69de29..7177ae3 100644 --- a/src/client-python/client.c +++ b/src/client-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/client-python/clientmodule.c b/src/client-python/clientmodule.c index e69de29..e4584dd 100644 --- a/src/client-python/clientmodule.c +++ b/src/client-python/clientmodule.c @@ -0,0 +1,42 @@ +/* + 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" + +static PyMethodDef module_methods[] = { + /* method_name, func, flags, doc_string */ + /* 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 } +}; + +#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ +#define PyMODINIT_FUNC void +#endif +PyMODINIT_FUNC +init_reportclient(void) +{ + PyObject *m = Py_InitModule("_reportclient", module_methods); + if (!m) + printf("m == NULL\n"); +} diff --git a/src/client-python/common.h b/src/client-python/common.h index e69de29..02f685f 100644 --- a/src/client-python/common.h +++ b/src/client-python/common.h @@ -0,0 +1,27 @@ +/* + 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 + +#include "client.h" +/* module-level functions */ +/* 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);