Skip to content

Commit

Permalink
Port reportclient to python3
Browse files Browse the repository at this point in the history
Related to #172, rhbz#1014684.

Signed-off-by: Martin Milata <mmilata@redhat.com>
  • Loading branch information
mmilata committed Mar 5, 2015
1 parent 39caef1 commit d4c6fc9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
1 change: 1 addition & 0 deletions libreport.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
%files python3
%defattr(-,root,root,-)
%{python3_sitearch}/report/*
%{python3_sitearch}/reportclient/*

%files cli
%defattr(-,root,root,-)
Expand Down
39 changes: 27 additions & 12 deletions src/client-python/reportclient/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
clientexecdir = $(pyexecdir)/reportclient

clientexec_PYTHON = \
PYFILES = \
__init__.py \
debuginfo.py \
dnfdebuginfo.py \
yumdebuginfo.py

clientexec_LTLIBRARIES = _reportclient.la
py2clientdir = $(pyexecdir)/reportclient
py3clientdir = $(py3execdir)/reportclient

py2client_PYTHON = $(PYFILES)
py3client_PYTHON = $(PYFILES)

_reportclient_la_SOURCES = \
py2client_LTLIBRARIES = _reportclient.la
py3client_LTLIBRARIES = _reportclient3.la

PYEXTFILES = \
clientmodule.c \
client.c \
common.h
_reportclient_la_CPPFLAGS = \
-I$(srcdir)/../../include/report -I$(srcdir)/../../include \

PYEXTCPPFLAGS = \
-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)"' \
$(GLIB_CFLAGS) \
$(PYTHON_CFLAGS) \
-D_GNU_SOURCE \
-fPIE
_reportclient_la_LDFLAGS = \

PYEXTLDFLAGS = \
-module \
-avoid-version \
-export-symbols-regex init_reportclient \
-Wl,-z,relro -Wl,-z,now
_reportclient_la_LIBADD = \
../../lib/libreport.la

_reportclient_la_SOURCES = $(PYEXTFILES)
_reportclient_la_CPPFLAGS = $(PYEXTCPPFLAGS) $(PYTHON_CFLAGS)
_reportclient_la_LDFLAGS = $(PYEXTLDFLAGS) \
-export-symbols-regex init_reportclient
_reportclient_la_LIBADD = ../../lib/libreport.la

_reportclient3_la_SOURCES = $(PYEXTFILES)
_reportclient3_la_CPPFLAGS = $(PYEXTCPPFLAGS) $(PYTHON3_CFLAGS)
_reportclient3_la_LDFLAGS = $(PYEXTLDFLAGS) \
-export-symbols-regex PyInit__reportclient3
_reportclient3_la_LIBADD = ../../lib/libreport.la

_reportclient.so: $(clientexec_LTLIBRARIES)
ln -sf $(abs_builddir)/.libs/$@ ./
Expand Down
7 changes: 5 additions & 2 deletions src/client-python/reportclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
# 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._reportclient import *

import shutil
import sys
import os

if sys.version_info[0] == 2:
from reportclient._reportclient import *
else:
from reportclient._reportclient3 import *

tmpdir = None

# everything was ok
Expand Down
28 changes: 23 additions & 5 deletions src/client-python/reportclient/clientmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,31 @@ static PyMethodDef module_methods[] = {
{ NULL }
};

#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#if PY_MAJOR_VERSION >= 3
#define MOD_ERROR_VAL NULL
#define MOD_SUCCESS_VAL(val) val
#define MOD_INIT PyMODINIT_FUNC PyInit__reportclient3(void)
#define MOD_DEF(ob, name, doc, methods) \
static struct PyModuleDef moduledef = { \
PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
ob = PyModule_Create(&moduledef);
#else
#define MOD_ERROR_VAL
#define MOD_SUCCESS_VAL(val)
#define MOD_INIT void init_reportclient(void)
#define MOD_DEF(ob, name, doc, methods) \
ob = Py_InitModule3(name, methods, doc);
#endif
PyMODINIT_FUNC
init_reportclient(void)

MOD_INIT
{
PyObject *m = Py_InitModule("_reportclient", module_methods);
PyObject *m;
MOD_DEF(m, "_reportclient", NULL, module_methods);
if (!m)
{
printf("m == NULL\n");
return MOD_ERROR_VAL;
}

return MOD_SUCCESS_VAL(m);
}
2 changes: 1 addition & 1 deletion src/client-python/reportclient/yumdebuginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def initialize_repositories(self):
# which causes artifacts on output
try:
setattr(r, "_async", False)
except (NameError, AttributeError), ex:

This comment has been minimized.

Copy link
@jfilak

jfilak Mar 6, 2015

Contributor

D'oh, I've avcidentally reverted a piece of your previous patches. Sorry.

except (NameError, AttributeError) as ex:
print(str(ex))
print(_("Can't disable async download, the output might contain artifacts!"))
except YumBaseError as ex:
Expand Down

0 comments on commit d4c6fc9

Please sign in to comment.