Ticket #11185: lsusb.py.diff

File lsusb.py.diff, 3.2 KB (added by Bruce Dubbs, 5 years ago)

Patch that fixes the problem.

  • lsusb.py

    old new  
    1212
    1313import os, sys, re, getopt
    1414
    15 # from __future__ import print_function
    16 
    1715# Global options
    1816showint = False
    1917showhubint = False
     
    5351                self.desc = str
    5452        def __repr__(self):
    5553                return self.desc
    56         def __cmp__(self, oth):
    57                 # Works only on 64bit systems:
    58                 #return self.pclass*0x10000+self.subclass*0x100+self.proto \
    59                 #       - oth.pclass*0x10000-oth.subclass*0x100-oth.proto
    60                 if self.pclass != oth.pclass:
    61                         return self.pclass - oth.pclass
    62                 if self.subclass != oth.subclass:
    63                         return self.subclass - oth.subclass
    64                 return self.proto - oth.proto
     54
     55        def __lt__(self, oth):
     56                return (self.pclass, self.subclass, self.proto) < \
     57                                (oth.pclass, oth.subclass, oth.proto)
     58        def __eq__(self, oth):
     59                return (self.pclass, self.subclass, self.proto) == \
     60                                (oth.pclass, oth.subclass, oth.proto)
    6561
    6662class UsbVendor:
    6763        "Container for USB Vendors"
     
    7066                self.vname = vname
    7167        def __repr__(self):
    7268                return self.vname
    73         def __cmp__(self, oth):
    74                 return self.vid - oth.vid
     69        def __lt__(self, oth):
     70                return self.vid < oth.vid
     71        def __eq__(self, oth):
     72                return self.vid == oth.vid
    7573
    7674class UsbProduct:
    7775        "Container for USB VID:PID devices"
     
    8179                self.pname = pname
    8280        def __repr__(self):
    8381                return self.pname
    84         def __cmp__(self, oth):
    85                 # Works only on 64bit systems:
    86                 # return self.vid*0x10000 + self.pid \
    87                 #       - oth.vid*0x10000 - oth.pid
    88                 if self.vid != oth.vid:
    89                         return self.vid - oth.vid
    90                 return self.pid - oth.pid
     82        def __lt__(self, oth):
     83                return (self.vid, self.pid) < (oth.vid, oth.pid)
     84        def __eq__(self, oth):
     85                return (self.vid, self.pid) == (oth.vid, oth.pid)
    9186
    9287usbvendors = []
    9388usbproducts = []
     
    107102        mode = 0
    108103        strg = ""
    109104        cstrg = ""
    110         for ln in file(usbids, "r").readlines():
     105        for ln in open(usbids, "r", errors="ignore"):
    111106                if ln[0] == '#':
    112107                        continue
    113108                ln = ln.rstrip('\n')
     
    146141
    147142def bin_search(first, last, item, list):
    148143        "binary search on list, returns -1 on fail, match idx otherwise, recursive"
    149         #print "bin_search(%i,%i)" % (first, last)
    150144        if first == last:
    151145                return -1
    152146        if first == last-1:
     
    233227        for nm in devlst:
    234228                dir = prefix + usbname
    235229                prep = ""
    236                 #print nm
    237230                idx = nm.find('/')
    238231                if idx != -1:
    239232                        prep = nm[:idx+1]
     
    404397                try:
    405398                        self.nointerfaces = int(readattr(fname, "bNumInterfaces"))
    406399                except:
    407                         #print "ERROR: %s/bNumInterfaces = %s" % (fname,
    408                         #               readattr(fname, "bNumInterfaces"))a
    409400                        self.nointerfaces = 0
    410401                try:
    411402                        self.driver = readlink(fname, "driver")
     
    421412                for dirent in os.listdir(prefix + self.fname):
    422413                        if not dirent[0:1].isdigit():
    423414                                continue
    424                         #print dirent
    425415                        if os.access(prefix + dirent + "/bInterfaceClass", os.R_OK):
    426416                                iface = UsbInterface(self, self.level+1)
    427417                                iface.read(dirent)
     
    532522def read_usb():
    533523        "Read toplevel USB entries and print"
    534524        for dirent in os.listdir(prefix):
    535                 #print dirent,
    536525                if not dirent[0:3] == "usb":
    537526                        continue
    538527                usbdev = UsbDevice(None, 0)
     
    590579                fix_usbclass()
    591580        except:
    592581                print(" WARNING: Failure to read usb.ids", file=sys.stderr)
    593                 #print >>sys.stderr, sys.exc_info()
    594582        read_usb()
    595583
    596584# Entry point