From 4becc237ee7d528daa4637548020376cc21761314ddd0698c0960c5fa9cc3ca4 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 22 Mar 2018 09:45:27 +0000 Subject: [PATCH] Accepting request 589977 from home:mwilck:hplip - photocard.py: fixed broken import statement (bsc#1071255) * added photocard-fix-import-error-for-pcardext.patch * spec file: fixed dependency for dbus-1-python (Leap42.2) - Use python3 on tumbleweed and SLE15/Leap15 (bsc#1071255) * add pcardext-python3-fixes.patch * add hplip-misc-missing-includes-and-definitions.patch * hp_ipp.h-add-missing-prototypes.patch * spec file: replace "/usr/bin/env python" and "/usr/bin/python" with desired interpreter * spec file: add py2/py3 selection macros * spec file: dropped python-openssl build dependency (not needed anymore) OBS-URL: https://build.opensuse.org/request/show/589977 OBS-URL: https://build.opensuse.org/package/show/Printing/hplip?expand=0&rev=151 --- hp_ipp.h-add-missing-prototypes.patch | 36 ++++++++ ...isc-missing-includes-and-definitions.patch | 62 +++++++++++++ hplip.changes | 19 ++++ hplip.spec | 86 +++++++++++++++---- pcardext-python3-fixes.patch | 81 +++++++++++++++++ photocard-fix-import-error-for-pcardext.patch | 27 ++++++ 6 files changed, 293 insertions(+), 18 deletions(-) create mode 100644 hp_ipp.h-add-missing-prototypes.patch create mode 100644 hplip-misc-missing-includes-and-definitions.patch create mode 100644 pcardext-python3-fixes.patch create mode 100644 photocard-fix-import-error-for-pcardext.patch diff --git a/hp_ipp.h-add-missing-prototypes.patch b/hp_ipp.h-add-missing-prototypes.patch new file mode 100644 index 0000000..689e066 --- /dev/null +++ b/hp_ipp.h-add-missing-prototypes.patch @@ -0,0 +1,36 @@ +From e69884e9581d3c6013389ac0efa4e3778dbbee68 Mon Sep 17 00:00:00 2001 +From: Martin Wilck +Date: Wed, 21 Mar 2018 23:56:41 +0100 +Subject: [PATCH] hp_ipp.h: add missing prototypes + +--- + protocol/hp_ipp.h | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/protocol/hp_ipp.h b/protocol/hp_ipp.h +index 3853f8432dae..24daf8b37a9a 100644 +--- a/protocol/hp_ipp.h ++++ b/protocol/hp_ipp.h +@@ -149,6 +149,7 @@ int auth_cancel_req = 0; // 0--> authentication cancel is not requested, + + + http_t* acquireCupsInstance(); ++void _releaseCupsInstance(); + const char *getCupsErrorString(int status); + void freePrinterList(printer_t *list); + +@@ -162,6 +163,11 @@ ipp_t * usbDoRequest(ipp_t *request, char* device_uri); + ipp_t * networkDoRequest(ipp_t *request, char* device_uri); + ipp_t * getDeviceStatusAttributes(char* device_uri, int *count); + int getCupsPrinters(printer_t **printer_list); ++int addCupsPrinter(char *name, char *device_uri, char *location, char *ppd_file, ++ char *model, char *info); ++int delCupsPrinter(char *pr_name); ++int setDefaultCupsPrinter(char *pr_name); ++int controlCupsPrinter(char *pr_name, int op); + + HPIPP_RESULT parseResponseHeader(char* header, int *content_length, int *chunked, int* header_size); + HPIPP_RESULT prepend_http_header(raw_ipp *raw_request); +-- +2.16.1 + diff --git a/hplip-misc-missing-includes-and-definitions.patch b/hplip-misc-missing-includes-and-definitions.patch new file mode 100644 index 0000000..416c49a --- /dev/null +++ b/hplip-misc-missing-includes-and-definitions.patch @@ -0,0 +1,62 @@ +From 6dd5de8c21284530a7d9716b979812446cc4eb79 Mon Sep 17 00:00:00 2001 +From: Martin Wilck +Date: Wed, 21 Mar 2018 23:56:05 +0100 +Subject: [PATCH] hplip: misc missing #includes and definitions + +--- + protocol/discovery/mdns.c | 1 + + protocol/discovery/mdns.h | 1 + + scan/sane/hpaio.c | 1 + + scan/sane/http.c | 1 + + 4 files changed, 4 insertions(+) + +diff --git a/protocol/discovery/mdns.c b/protocol/discovery/mdns.c +index 75ef0eab7214..c58d218390f5 100644 +--- a/protocol/discovery/mdns.c ++++ b/protocol/discovery/mdns.c +@@ -40,6 +40,7 @@ + #include + #include "mdns.h" + #include ++#include + #include + + /* Convert "www.google.com" to "3www6google3com". */ +diff --git a/protocol/discovery/mdns.h b/protocol/discovery/mdns.h +index 56d8847da28a..d64e668fe194 100644 +--- a/protocol/discovery/mdns.h ++++ b/protocol/discovery/mdns.h +@@ -105,5 +105,6 @@ static unsigned char* mdns_readMDL(unsigned char *p, unsigned char *normalized_m + static DNS_RECORD* send_and_receive(struct mdns_socket *mdns_sock, const char *name, + int query_type, int read_mode); + static int get_ipv4_address(const char *iface, struct in_addr *addr); ++int mdns_probe_nw_scanners(char* uris_buf, int buf_size, int *count); + #endif // _DISCOVERY_MDNS_H + +diff --git a/scan/sane/hpaio.c b/scan/sane/hpaio.c +index ae34cfb63fd9..28899d10bae3 100644 +--- a/scan/sane/hpaio.c ++++ b/scan/sane/hpaio.c +@@ -46,6 +46,7 @@ + #include "sclpml.h" + #include "escl.h" + #include "io.h" ++#include "mdns.h" + + #define DEBUG_DECLARE_ONLY + #include "sanei_debug.h" +diff --git a/scan/sane/http.c b/scan/sane/http.c +index 800df91bb3f3..ae5edf4c8fe8 100644 +--- a/scan/sane/http.c ++++ b/scan/sane/http.c +@@ -33,6 +33,7 @@ + + #include + #include ++#include + #include + #include + #include +-- +2.16.1 + diff --git a/hplip.changes b/hplip.changes index 356d59e..2a62c7e 100644 --- a/hplip.changes +++ b/hplip.changes @@ -1,3 +1,22 @@ +------------------------------------------------------------------- +Thu Mar 22 08:44:17 UTC 2018 - mwilck@suse.com + +- photocard.py: fixed broken import statement (bsc#1071255) + * added photocard-fix-import-error-for-pcardext.patch + * spec file: fixed dependency for dbus-1-python + +------------------------------------------------------------------- +Wed Mar 21 23:52:02 UTC 2018 - mwilck@suse.com + +- Use python3 on tumbleweed and SLE15/Leap15 (bsc#1071255) + * add pcardext-python3-fixes.patch + * add hplip-misc-missing-includes-and-definitions.patch + * hp_ipp.h-add-missing-prototypes.patch + * spec file: replace "/usr/bin/env python" and "/usr/bin/python" with + desired interpreter + * spec file: add py2/py3 selection macros + * spec file: dropped python-openssl build dependency (not needed anymore) + ------------------------------------------------------------------- Thu Oct 12 21:03:40 UTC 2017 - mgorse@suse.com diff --git a/hplip.spec b/hplip.spec index 8bcb97a..98e8a62 100644 --- a/hplip.spec +++ b/hplip.spec @@ -1,7 +1,7 @@ # # spec file for package hplip # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -16,6 +16,20 @@ # +%if 0%{suse_version} >= 1500 +%define pyversion 3 +%define pymod() python3-%{**} +%define pyver %py3_ver +%define pyexe /usr/bin/python3 +%define gobject gobject +%else +%define pyversion 2 +%define pymod() python-%{**} +%define pyver %py_ver +%define pyexe /usr/bin/python +%define gobject gobject2 +%endif + %if 0%{?suse_version} == 1315 && 0%{?is_opensuse} %define is_leap 1 %else @@ -79,6 +93,13 @@ Patch109: no-systray-failure-message.patch Patch200: hplip-mdns.patch # Patch201 makes MDNS lookups more robust by retrying queries: Patch201: hplip-mdns-retry-query.patch +# Python3 port: cleanup patches +Patch300: pcardext-python3-fixes.patch +Patch301: hplip-misc-missing-includes-and-definitions.patch +Patch302: hp_ipp.h-add-missing-prototypes.patch +# Fix import error for pcardext +Patch303: photocard-fix-import-error-for-pcardext.patch + BuildRequires: dbus-1-devel BuildRequires: fdupes BuildRequires: hicolor-icon-theme @@ -89,20 +110,20 @@ BuildRequires: libtool BuildRequires: libusb-1_0-devel BuildRequires: net-snmp-devel BuildRequires: pkgconfig +# BuildRequires: python-rpm-macros # All printer driver packages should have "BuildRequires: python-cups" # because python-cups installs special rpm macros that adds Provides tags # for the printer drivers supported by the package, # see https://bugzilla.novell.com/show_bug.cgi?id=735865 -BuildRequires: python-cups -BuildRequires: python-devel -BuildRequires: python-openssl +BuildRequires: %{pymod cups} +BuildRequires: %{pymod devel} %if %use_qt5 -BuildRequires: python-qt5-devel +BuildRequires: %{pymod qt5-devel} %else +BuildRequires: %{pymod qt4} BuildRequires: libqt4-devel -BuildRequires: python-qt4 %endif -BuildRequires: python-xml +BuildRequires: %{pymod xml} BuildRequires: readline-devel BuildRequires: update-desktop-files # Require the exact matching version-release of the hpijs sub-package to make sure @@ -118,7 +139,11 @@ Requires: %{name}-sane = %{version}-%{release} # The dbus stuff in HPLIP requires the Python module gobject # but there is no automated RPM requirement for python-gobject2, # see https://answers.launchpad.net/hplip/+question/30741 +%if 0%{pyversion} == 3 +Requires: dbus-1-python3 >= 0.80 +%else Requires: dbus-1-python >= 0.80 +%endif # Because foomatic-rip-hplip has CVE-2011-2697 (bnc#698451) # plus a leftover in CVE-2004-0801 (bnc#59233) # foomatic-rip-hplip is no longer installed and foomatic-rip @@ -139,13 +164,13 @@ Requires: foomatic-filters # (see the comment for the hplip-hpijs sub-package below). # Therefore the hplip main package which is intended # to get "all the HPLIP stuff" installed has the RPM requirement: +Requires: %{pymod %gobject} Requires: ghostscript -Requires: python-gobject2 %if %use_qt5 -Requires: python-qt5 +Requires: %{pymod qt5} %else -Requires: python-qt4 +Requires: %{pymod qt4} %endif # Require special Python stuff (which pulls in Python base stuff). # At least since openSUSE 11.1 and SLE11 pyxml is no longer required @@ -153,7 +178,7 @@ Requires: python-qt4 # see https://answers.launchpad.net/hplip/+question/25696) # but meanwhile python-xml alone is sufficient for "import xml.parsers.expat" # see https://bugzilla.novell.com/show_bug.cgi?id=656779#c3 -Requires: python-xml +Requires: %{pymod xml} Requires(post): %{_bindir}/find Requires(post): /bin/grep Requires(post): /bin/sed @@ -370,9 +395,19 @@ This sub-package is only required by developers. # Patch108 add_missing_includes_and_define_GNU_SOURCE.patch adds missing '#include <...>' # and missing '#define _GNU_SOURCE' see https://bugs.launchpad.net/hplip/+bug/1456590 %patch108 -p1 -b .add_missing_includes_and_define_GNU_SOURCE.orig -%patch109 -p1 -b systemtray.py.orig +%patch109 -p1 -b .systemtray.py.orig %patch200 -p1 -b .mdns %patch201 -p1 -b .mdns-retry +%patch300 -p1 -b .pcardext-python3 +%patch301 -p1 -b .misc-headers +%patch302 -p1 -b .hp_ipp_missing_prototypes +%patch303 -p1 -b .photocard_import + +# replace "env" shebang and "/usr/bin/python" with real executable +find . -name '*.py' -o -name pstotiff | \ + xargs -n 1 sed -i '1s,^#!\(/usr/bin/env python\|/usr/bin/python\),#!%{pyexe},' +sed -i 's,/usr/bin/python\>,%{pyexe},' \ + data/rules/* %build # If AUTOMAKE='automake --foreign' is not set, autoreconf (in fact automake) @@ -437,7 +472,8 @@ export CXXFLAGS="%{optflags} -fno-strict-aliasing" --with-mimedir=%{_sysconfdir}/cups \ --with-docdir=%{_defaultdocdir}/%{name} \ --with-htmldir==%{_defaultdocdir}/%{name} \ - CFLAGS='%{optflags}' + CFLAGS='%{optflags}' \ + PYTHON=%{pyexe} make %install @@ -450,17 +486,31 @@ make DESTDIR=%{buildroot} install # which results longer program startup time and waste of CPU for compiling, # see https://en.opensuse.org/openSUSE:Packaging_Python#Byte_Compiled_Files # and http://lists.opensuse.org/opensuse-packaging/2014-10/msg00028.html + +%if 0%{pyversion} == 3 +# Make and install .pyc files: +%py3_compile %{buildroot}%{_datadir}/hplip +# Make and install .pyo files: +%py3_compile -O %{buildroot}%{_datadir}/hplip +%else # Make and install .pyc files: %py_compile %{buildroot}%{_datadir}/hplip # Make and install .pyo files: %py_compile -O %{buildroot}%{_datadir}/hplip +%endif + # Hardlink .pyc and .pyo when they have same content. # Do not run "fdupes buildroot/_datadir/hplip" because # fdupes will link any files with same content there # which can have unexpected side-effects, compare # https://bugzilla.opensuse.org/show_bug.cgi?id=784670 for pyc in $( find %{buildroot}%{_datadir}/hplip -name '*.pyc' ) -do pyo="${pyc%.pyc}.pyo" +do +%if 0%{pyversion} == 3 + pyo="${pyc%.pyc}.opt-1.pyc" +%else + pyo="${pyc%.pyc}.pyo" +%endif if test -f $pyo && cmp -s $pyc $pyo then echo hardlinking $pyc and $pyo because both have same content ln -f $pyc $pyo @@ -708,10 +758,10 @@ exit 0 %{_bindir}/hp-unload %{_bindir}/hp-upgrade %{_bindir}/hp-wificonfig -%{_libdir}/python%{py_ver}/site-packages/cupsext.* -%{_libdir}/python%{py_ver}/site-packages/hpmudext.* -%{_libdir}/python%{py_ver}/site-packages/pcardext.* -%{_libdir}/python%{py_ver}/site-packages/scanext.* +%{_libdir}/python%{pyver}/site-packages/cupsext.* +%{_libdir}/python%{pyver}/site-packages/hpmudext.* +%{_libdir}/python%{pyver}/site-packages/pcardext.* +%{_libdir}/python%{pyver}/site-packages/scanext.* %dir %{_libexecdir}/cups %dir %{_libexecdir}/cups/backend %{_libexecdir}/cups/backend/hpfax diff --git a/pcardext-python3-fixes.patch b/pcardext-python3-fixes.patch new file mode 100644 index 0000000..89ee62f --- /dev/null +++ b/pcardext-python3-fixes.patch @@ -0,0 +1,81 @@ +From 74ed15a16e7564d0665afc68defbd6d03bdff21d Mon Sep 17 00:00:00 2001 +From: Martin Wilck +Date: Wed, 21 Mar 2018 23:55:12 +0100 +Subject: [PATCH] pcardext: python3 fixes + +--- + pcard/pcardext/pcardext.c | 36 ++++++++++++++++++++++++++++++++++-- + 1 file changed, 34 insertions(+), 2 deletions(-) + +diff --git a/pcard/pcardext/pcardext.c b/pcard/pcardext/pcardext.c +index c1a8273e4359..cdf260d62223 100644 +--- a/pcard/pcardext/pcardext.c ++++ b/pcard/pcardext/pcardext.c +@@ -36,6 +36,12 @@ typedef int Py_ssize_t; + #define PY_SSIZE_T_MIN INT_MIN + #endif + ++#if PY_MAJOR_VERSION >= 3 ++#define PyString_AsStringAndSize PyBytes_AsStringAndSize ++#define PyString_FromStringAndSize PyBytes_FromStringAndSize ++#define PyInt_AS_LONG PyLong_AS_LONG ++#endif ++ + int verbose=0; + + PyObject * readsectorFunc = NULL; +@@ -78,8 +84,11 @@ int WriteSector(int sector, int nsector, void *buf, int size ) + + if( writesectorFunc ) + { ++#if PY_MAJOR_VERSION >= 3 + result = PyObject_CallFunction( writesectorFunc, "iis#", sector, nsector, buf, size ); +- ++#else ++ result = PyObject_CallFunction( writesectorFunc, "iiy#", sector, nsector, buf, size ); ++#endif + return PyInt_AS_LONG( result ); + } + +@@ -230,9 +239,31 @@ static PyMethodDef pcardext_methods[] = + { NULL, NULL } + }; + +- + static char pcardext_documentation[] = "Python extension for HP photocard services"; + ++#if PY_MAJOR_VERSION >= 3 ++static struct PyModuleDef moduledef = { ++ .m_base = PyModuleDef_HEAD_INIT, ++ .m_name = "pcardext", ++ .m_doc = pcardext_documentation, ++ .m_size = -1, ++ .m_methods = pcardext_methods, ++ .m_slots = NULL, ++ .m_traverse = NULL, ++ .m_clear = NULL, ++ .m_free = NULL, ++}; ++ ++PyMODINIT_FUNC ++PyInit_pcardext( void ) ++{ ++ PyObject *module = PyModule_Create2(&moduledef, PYTHON_API_VERSION); ++ ++ return module; ++} ++ ++#else ++ + void initpcardext( void ) + { + PyObject * mod = Py_InitModule4( "pcardext", pcardext_methods, +@@ -243,4 +274,5 @@ void initpcardext( void ) + return; + } + ++#endif + +-- +2.16.1 + diff --git a/photocard-fix-import-error-for-pcardext.patch b/photocard-fix-import-error-for-pcardext.patch new file mode 100644 index 0000000..ecbd06b --- /dev/null +++ b/photocard-fix-import-error-for-pcardext.patch @@ -0,0 +1,27 @@ +From adca775071398e0dbb87a972798ee82975794640 Mon Sep 17 00:00:00 2001 +From: Martin Wilck +Date: Thu, 22 Mar 2018 09:30:38 +0100 +Subject: [PATCH] photocard: fix import error for pcardext + +Due to the way the C module is installed, explicit relative +import doesn't work for pcardext. +--- + pcard/photocard.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/pcard/photocard.py b/pcard/photocard.py +index 913dc4e98d7f..2c7315883c8d 100644 +--- a/pcard/photocard.py ++++ b/pcard/photocard.py +@@ -30,7 +30,7 @@ from base.codes import * + from base import device, utils, exif + + try: +- from . import pcardext ++ import pcardext + except ImportError: + if not os.getenv("HPLIP_BUILD"): + log.error("PCARDEXT could not be loaded. Please check HPLIP installation.") +-- +2.16.1 +