system-config-printer-device-sorting.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. diff -up system-config-printer-1.5.7/cupshelpers/cupshelpers.py.device-sorting system-config-printer-1.5.7/cupshelpers/cupshelpers.py
  2. --- system-config-printer-1.5.7/cupshelpers/cupshelpers.py.device-sorting 2015-04-23 16:05:58.000000000 +0100
  3. +++ system-config-printer-1.5.7/cupshelpers/cupshelpers.py 2015-05-26 09:57:43.583569255 +0100
  4. @@ -547,68 +547,68 @@ class Device:
  5. Compare devices by order of preference.
  6. """
  7. if other == None:
  8. - return 1
  9. + return True
  10. if self.is_class != other.is_class:
  11. if other.is_class:
  12. - return 1
  13. - return -1
  14. + return True
  15. + return False
  16. if not self.is_class and (self.type != other.type):
  17. # "hp"/"hpfax" before "usb" before * before "parallel" before
  18. # "serial"
  19. if other.type == "serial":
  20. - return 1
  21. + return True
  22. if self.type == "serial":
  23. - return -1
  24. + return False
  25. if other.type == "parallel":
  26. - return 1
  27. + return True
  28. if self.type == "parallel":
  29. - return -1
  30. + return False
  31. if other.type == "hp":
  32. - return -1
  33. + return False
  34. if self.type == "hp":
  35. - return 1
  36. + return True
  37. if other.type == "hpfax":
  38. - return -1
  39. + return False
  40. if self.type == "hpfax":
  41. - return 1
  42. + return True
  43. if other.type == "dnssd":
  44. - return -1
  45. + return False
  46. if self.type == "dnssd":
  47. - return 1
  48. + return True
  49. if other.type == "socket":
  50. - return -1
  51. + return False
  52. if self.type == "socket":
  53. - return 1
  54. + return True
  55. if other.type == "lpd":
  56. - return -1
  57. + return False
  58. if self.type == "lpd":
  59. - return 1
  60. + return True
  61. if other.type == "ipps":
  62. - return -1
  63. + return False
  64. if self.type == "ipps":
  65. - return 1
  66. + return True
  67. if other.type == "ipp":
  68. - return -1
  69. + return False
  70. if self.type == "ipp":
  71. - return 1
  72. + return True
  73. if other.type == "usb":
  74. - return -1
  75. + return False
  76. if self.type == "usb":
  77. - return 1
  78. + return True
  79. if self.type == "dnssd" and other.type == "dnssd":
  80. if other.uri.find("._pdl-datastream") != -1: # Socket
  81. - return -1
  82. + return False
  83. if self.uri.find("._pdl-datastream") != -1:
  84. - return 1
  85. + return True
  86. if other.uri.find("._printer") != -1: # LPD
  87. - return -1
  88. + return False
  89. if self.uri.find("._printer") != -1:
  90. - return 1
  91. + return True
  92. if other.uri.find("._ipp") != -1: # IPP
  93. - return -1
  94. + return False
  95. if self.uri.find("._ipp") != -1:
  96. - return 1
  97. + return True
  98. result = bool(self.id) < bool(other.id)
  99. if not result:
  100. result = self.info < other.info
  101. diff -up system-config-printer-1.5.7/test_PhysicalDevice.py.device-sorting system-config-printer-1.5.7/test_PhysicalDevice.py
  102. --- system-config-printer-1.5.7/test_PhysicalDevice.py.device-sorting 2015-04-23 16:22:28.000000000 +0100
  103. +++ system-config-printer-1.5.7/test_PhysicalDevice.py 2015-05-26 09:57:43.583569255 +0100
  104. @@ -49,3 +49,21 @@ def run_test():
  105. phys.add_device (device)
  106. devices = phys.get_devices ()
  107. assert devices[0].uri.startswith ("hp")
  108. +
  109. + dev1 = cupshelpers.Device("hp:/usb/HP_Color_LaserJet_CP3525?serial=CNCTC8G0QX",
  110. + **{'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;',
  111. + 'device-make-and-model':'HP Color LaserJet CP3525',
  112. + 'device-class':'direct'})
  113. + phys = PhysicalDevice (dev1)
  114. + dev2 = cupshelpers.Device('usb://HP/Color%20LaserJet%20CP3525?serial=CNCTC8G0QX',
  115. + **{'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;',
  116. + 'device-make-and-model':'HP Color LaserJet CP3525',
  117. + 'device-class':'direct'})
  118. +
  119. + # hp device should sort < usb device
  120. + assert dev1 < dev2
  121. +
  122. + phys.add_device (dev2)
  123. + devices = phys.get_devices ()
  124. + assert devices[0] < devices[1]
  125. + assert devices[0].uri.startswith ("hp")