Fixed device sorting (bug #1210733).

This commit is contained in:
Tim Waugh 2015-05-26 10:00:01 +01:00
parent 902952def3
commit 8ee96f3819
2 changed files with 134 additions and 1 deletions

View File

@ -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")

View File

@ -7,12 +7,13 @@
Summary: A printer administration tool Summary: A printer administration tool
Name: system-config-printer Name: system-config-printer
Version: 1.5.7 Version: 1.5.7
Release: 2%{?dist} Release: 3%{?dist}
License: GPLv2+ License: GPLv2+
URL: http://cyberelk.net/tim/software/system-config-printer/ URL: http://cyberelk.net/tim/software/system-config-printer/
Group: System Environment/Base Group: System Environment/Base
Source0: http://cyberelk.net/tim/data/system-config-printer/1.5/%{name}-%{version}.tar.xz Source0: http://cyberelk.net/tim/data/system-config-printer/1.5/%{name}-%{version}.tar.xz
Patch1: system-config-printer-shbang.patch Patch1: system-config-printer-shbang.patch
Patch2: system-config-printer-device-sorting.patch
BuildRequires: cups-devel >= 1.2 BuildRequires: cups-devel >= 1.2
BuildRequires: desktop-file-utils >= 0.2.92 BuildRequires: desktop-file-utils >= 0.2.92
@ -85,6 +86,9 @@ printers.
# Fixed shbang line in udev-add-printer (trac #244). # Fixed shbang line in udev-add-printer (trac #244).
%patch1 -p1 -b .shbang %patch1 -p1 -b .shbang
# Fixed device sorting (bug #1210733).
%patch2 -p1 -b .device-sorting
%build %build
%configure --with-udev-rules %configure --with-udev-rules
make %{?_smp_mflags} make %{?_smp_mflags}
@ -187,6 +191,9 @@ touch %buildroot%{_localstatedir}/run/udev-configure-printer/usb-uris
exit 0 exit 0
%changelog %changelog
* Tue May 26 2015 Tim Waugh <twaugh@redhat.com> - 1.5.7-3
- Fixed device sorting (bug #1210733).
* Tue May 26 2015 Tim Waugh <twaugh@redhat.com> - 1.5.7-2 * Tue May 26 2015 Tim Waugh <twaugh@redhat.com> - 1.5.7-2
- Fixed shbang line in udev-add-printer (trac #244). - Fixed shbang line in udev-add-printer (trac #244).