From 8ee96f3819d240c634a8b0bd562af118f9c88642 Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Tue, 26 May 2015 10:00:01 +0100 Subject: [PATCH] Fixed device sorting (bug #1210733). --- system-config-printer-device-sorting.patch | 126 +++++++++++++++++++++ system-config-printer.spec | 9 +- 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 system-config-printer-device-sorting.patch diff --git a/system-config-printer-device-sorting.patch b/system-config-printer-device-sorting.patch new file mode 100644 index 0000000..20a6696 --- /dev/null +++ b/system-config-printer-device-sorting.patch @@ -0,0 +1,126 @@ +diff -up system-config-printer-1.5.7/cupshelpers/cupshelpers.py.device-sorting system-config-printer-1.5.7/cupshelpers/cupshelpers.py +--- system-config-printer-1.5.7/cupshelpers/cupshelpers.py.device-sorting 2015-04-23 16:05:58.000000000 +0100 ++++ system-config-printer-1.5.7/cupshelpers/cupshelpers.py 2015-05-26 09:57:43.583569255 +0100 +@@ -547,68 +547,68 @@ class Device: + Compare devices by order of preference. + """ + if other == None: +- return 1 ++ return True + + if self.is_class != other.is_class: + if other.is_class: +- return 1 +- return -1 ++ return True ++ return False + if not self.is_class and (self.type != other.type): + # "hp"/"hpfax" before "usb" before * before "parallel" before + # "serial" + if other.type == "serial": +- return 1 ++ return True + if self.type == "serial": +- return -1 ++ return False + if other.type == "parallel": +- return 1 ++ return True + if self.type == "parallel": +- return -1 ++ return False + if other.type == "hp": +- return -1 ++ return False + if self.type == "hp": +- return 1 ++ return True + if other.type == "hpfax": +- return -1 ++ return False + if self.type == "hpfax": +- return 1 ++ return True + if other.type == "dnssd": +- return -1 ++ return False + if self.type == "dnssd": +- return 1 ++ return True + if other.type == "socket": +- return -1 ++ return False + if self.type == "socket": +- return 1 ++ return True + if other.type == "lpd": +- return -1 ++ return False + if self.type == "lpd": +- return 1 ++ return True + if other.type == "ipps": +- return -1 ++ return False + if self.type == "ipps": +- return 1 ++ return True + if other.type == "ipp": +- return -1 ++ return False + if self.type == "ipp": +- return 1 ++ return True + if other.type == "usb": +- return -1 ++ return False + if self.type == "usb": +- return 1 ++ return True + if self.type == "dnssd" and other.type == "dnssd": + if other.uri.find("._pdl-datastream") != -1: # Socket +- return -1 ++ return False + if self.uri.find("._pdl-datastream") != -1: +- return 1 ++ return True + if other.uri.find("._printer") != -1: # LPD +- return -1 ++ return False + if self.uri.find("._printer") != -1: +- return 1 ++ return True + if other.uri.find("._ipp") != -1: # IPP +- return -1 ++ return False + if self.uri.find("._ipp") != -1: +- return 1 ++ return True + result = bool(self.id) < bool(other.id) + if not result: + result = self.info < other.info +diff -up system-config-printer-1.5.7/test_PhysicalDevice.py.device-sorting system-config-printer-1.5.7/test_PhysicalDevice.py +--- system-config-printer-1.5.7/test_PhysicalDevice.py.device-sorting 2015-04-23 16:22:28.000000000 +0100 ++++ system-config-printer-1.5.7/test_PhysicalDevice.py 2015-05-26 09:57:43.583569255 +0100 +@@ -49,3 +49,21 @@ def run_test(): + phys.add_device (device) + devices = phys.get_devices () + assert devices[0].uri.startswith ("hp") ++ ++ dev1 = cupshelpers.Device("hp:/usb/HP_Color_LaserJet_CP3525?serial=CNCTC8G0QX", ++ **{'device-id':'MFG:Hewlett-Packard;CMD:PJL,MLC,BIDI-ECP,PJL,PCLXL,PCL,POSTSCRIPT,PDF;MDL:HP Color LaserJet CP3525;CLS:PRINTER;DES:Hewlett-Packard Color LaserJet CP3525;', ++ 'device-make-and-model':'HP Color LaserJet CP3525', ++ 'device-class':'direct'}) ++ phys = PhysicalDevice (dev1) ++ dev2 = cupshelpers.Device('usb://HP/Color%20LaserJet%20CP3525?serial=CNCTC8G0QX', ++ **{'device-id':'MFG:Hewlett-Packard;CMD:PJL,MLC,BIDI-ECP,PJL,PCLXL,PCL,POSTSCRIPT,PDF;MDL:HP Color LaserJet CP3525;CLS:PRINTER;DES:Hewlett-Packard Color LaserJet CP3525;', ++ 'device-make-and-model':'HP Color LaserJet CP3525', ++ 'device-class':'direct'}) ++ ++ # hp device should sort < usb device ++ assert dev1 < dev2 ++ ++ phys.add_device (dev2) ++ devices = phys.get_devices () ++ assert devices[0] < devices[1] ++ assert devices[0].uri.startswith ("hp") diff --git a/system-config-printer.spec b/system-config-printer.spec index a144627..4b6a119 100644 --- a/system-config-printer.spec +++ b/system-config-printer.spec @@ -7,12 +7,13 @@ Summary: A printer administration tool Name: system-config-printer Version: 1.5.7 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2+ URL: http://cyberelk.net/tim/software/system-config-printer/ Group: System Environment/Base Source0: http://cyberelk.net/tim/data/system-config-printer/1.5/%{name}-%{version}.tar.xz Patch1: system-config-printer-shbang.patch +Patch2: system-config-printer-device-sorting.patch BuildRequires: cups-devel >= 1.2 BuildRequires: desktop-file-utils >= 0.2.92 @@ -85,6 +86,9 @@ printers. # Fixed shbang line in udev-add-printer (trac #244). %patch1 -p1 -b .shbang +# Fixed device sorting (bug #1210733). +%patch2 -p1 -b .device-sorting + %build %configure --with-udev-rules make %{?_smp_mflags} @@ -187,6 +191,9 @@ touch %buildroot%{_localstatedir}/run/udev-configure-printer/usb-uris exit 0 %changelog +* Tue May 26 2015 Tim Waugh - 1.5.7-3 +- Fixed device sorting (bug #1210733). + * Tue May 26 2015 Tim Waugh - 1.5.7-2 - Fixed shbang line in udev-add-printer (trac #244).