Blame SOURCES/0004-lsusb.py-fix-up-Python-3-conversion.patch

67abd2
From a7c25eadbc998bf359e5b7dac03aaea8c30d2932 Mon Sep 17 00:00:00 2001
67abd2
From: Georg Brandl <georg@python.org>
67abd2
Date: Thu, 17 May 2018 08:51:27 +0200
67abd2
Subject: [PATCH 4/9] lsusb.py: fix up Python 3 conversion
67abd2
67abd2
- Use open() and ignore encoding errors
67abd2
- Replace removed __cmp__ by rich comparison methods
67abd2
- Convert commented-out print statements, remove unused future import
67abd2
67abd2
Fixes #68
67abd2
---
67abd2
 lsusb.py.in | 50 ++++++++++++++++++++++----------------------------
67abd2
 1 file changed, 22 insertions(+), 28 deletions(-)
67abd2
67abd2
diff --git a/lsusb.py.in b/lsusb.py.in
67abd2
index 0f4d318..083b512 100644
67abd2
--- a/lsusb.py.in
67abd2
+++ b/lsusb.py.in
67abd2
@@ -12,8 +12,6 @@
67abd2
 
67abd2
 import os, sys, re, getopt
67abd2
 
67abd2
-# from __future__ import print_function
67abd2
-
67abd2
 # Global options
67abd2
 showint = False
67abd2
 showhubint = False
67abd2
@@ -53,15 +51,12 @@ class UsbClass:
67abd2
 		self.desc = str
67abd2
 	def __repr__(self):
67abd2
 		return self.desc
67abd2
-	def __cmp__(self, oth):
67abd2
-		# Works only on 64bit systems:
67abd2
-		#return self.pclass*0x10000+self.subclass*0x100+self.proto \
67abd2
-		#	- oth.pclass*0x10000-oth.subclass*0x100-oth.proto
67abd2
-		if self.pclass != oth.pclass:
67abd2
-			return self.pclass - oth.pclass
67abd2
-		if self.subclass != oth.subclass:
67abd2
-			return self.subclass - oth.subclass
67abd2
-		return self.proto - oth.proto
67abd2
+	def __lt__(self, oth):
67abd2
+		return (self.pclass, self.subclass, self.proto) < \
67abd2
+				(oth.pclass, oth.subclass, oth.proto)
67abd2
+	def __eq__(self, oth):
67abd2
+		return (self.pclass, self.subclass, self.proto) == \
67abd2
+				(oth.pclass, oth.subclass, oth.proto)
67abd2
 
67abd2
 class UsbVendor:
67abd2
 	"Container for USB Vendors"
67abd2
@@ -70,8 +65,10 @@ class UsbVendor:
67abd2
 		self.vname = vname
67abd2
 	def __repr__(self):
67abd2
 		return self.vname
67abd2
-	def __cmp__(self, oth):
67abd2
-		return self.vid - oth.vid
67abd2
+	def __lt__(self, oth):
67abd2
+		return self.vid < oth.vid
67abd2
+	def __eq__(self, oth):
67abd2
+		return self.vid == oth.vid
67abd2
 
67abd2
 class UsbProduct:
67abd2
 	"Container for USB VID:PID devices"
67abd2
@@ -81,13 +78,10 @@ class UsbProduct:
67abd2
 		self.pname = pname
67abd2
 	def __repr__(self):
67abd2
 		return self.pname
67abd2
-	def __cmp__(self, oth):
67abd2
-		# Works only on 64bit systems:
67abd2
-		# return self.vid*0x10000 + self.pid \
67abd2
-		#	- oth.vid*0x10000 - oth.pid
67abd2
-		if self.vid != oth.vid:
67abd2
-			return self.vid - oth.vid
67abd2
-		return self.pid - oth.pid
67abd2
+	def __lt__(self, oth):
67abd2
+		return (self.vid, self.pid) < (oth.vid, oth.pid)
67abd2
+	def __eq__(self, oth):
67abd2
+		return (self.vid, self.pid) == (oth.vid, oth.pid)
67abd2
 
67abd2
 usbvendors = []
67abd2
 usbproducts = []
67abd2
@@ -107,7 +101,7 @@ def parse_usb_ids():
67abd2
 	mode = 0
67abd2
 	strg = ""
67abd2
 	cstrg = ""
67abd2
-	for ln in file(usbids, "r").readlines():
67abd2
+	for ln in open(usbids, "r", errors="ignore"):
67abd2
 		if ln[0] == '#':
67abd2
 			continue
67abd2
 		ln = ln.rstrip('\n')
67abd2
@@ -146,7 +140,7 @@ def parse_usb_ids():
67abd2
 
67abd2
 def bin_search(first, last, item, list):
67abd2
 	"binary search on list, returns -1 on fail, match idx otherwise, recursive"
67abd2
-	#print "bin_search(%i,%i)" % (first, last)
67abd2
+	#print("bin_search(%i,%i)" % (first, last))
67abd2
 	if first == last:
67abd2
 		return -1
67abd2
 	if first == last-1:
67abd2
@@ -233,7 +227,7 @@ def find_dev(driver, usbname):
67abd2
 	for nm in devlst:
67abd2
 		dir = prefix + usbname
67abd2
 		prep = ""
67abd2
-		#print nm
67abd2
+		#print(nm)
67abd2
 		idx = nm.find('/')
67abd2
 		if idx != -1:
67abd2
 			prep = nm[:idx+1]
67abd2
@@ -404,8 +398,8 @@ class UsbDevice:
67abd2
 		try:
67abd2
 			self.nointerfaces = int(readattr(fname, "bNumInterfaces"))
67abd2
 		except:
67abd2
-			#print "ERROR: %s/bNumInterfaces = %s" % (fname,
67abd2
-			#		readattr(fname, "bNumInterfaces"))a
67abd2
+			#print("ERROR: %s/bNumInterfaces = %s" % (fname,
67abd2
+			#		readattr(fname, "bNumInterfaces")))
67abd2
 			self.nointerfaces = 0
67abd2
 		try:
67abd2
 			self.driver = readlink(fname, "driver")
67abd2
@@ -421,7 +415,7 @@ class UsbDevice:
67abd2
 		for dirent in os.listdir(prefix + self.fname):
67abd2
 			if not dirent[0:1].isdigit():
67abd2
 				continue
67abd2
-			#print dirent
67abd2
+			#print(dirent)
67abd2
 			if os.access(prefix + dirent + "/bInterfaceClass", os.R_OK):
67abd2
 				iface = UsbInterface(self, self.level+1)
67abd2
 				iface.read(dirent)
67abd2
@@ -532,7 +526,7 @@ def usage():
67abd2
 def read_usb():
67abd2
 	"Read toplevel USB entries and print"
67abd2
 	for dirent in os.listdir(prefix):
67abd2
-		#print dirent,
67abd2
+		#print(dirent)
67abd2
 		if not dirent[0:3] == "usb":
67abd2
 			continue
67abd2
 		usbdev = UsbDevice(None, 0)
67abd2
@@ -590,7 +584,7 @@ def main(argv):
67abd2
 		fix_usbclass()
67abd2
 	except:
67abd2
 		print(" WARNING: Failure to read usb.ids", file=sys.stderr)
67abd2
-		#print >>sys.stderr, sys.exc_info()
67abd2
+		#print(sys.exc_info(), file=sys.stderr)
67abd2
 	read_usb()
67abd2
 
67abd2
 # Entry point
67abd2
-- 
67abd2
2.14.4
67abd2