Ticket #11185: lsusb.py.diff
File lsusb.py.diff, 3.2 KB (added by , 5 years ago) |
---|
-
lsusb.py
old new 12 12 13 13 import os, sys, re, getopt 14 14 15 # from __future__ import print_function16 17 15 # Global options 18 16 showint = False 19 17 showhubint = False … … 53 51 self.desc = str 54 52 def __repr__(self): 55 53 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) 65 61 66 62 class UsbVendor: 67 63 "Container for USB Vendors" … … 70 66 self.vname = vname 71 67 def __repr__(self): 72 68 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 75 73 76 74 class UsbProduct: 77 75 "Container for USB VID:PID devices" … … 81 79 self.pname = pname 82 80 def __repr__(self): 83 81 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) 91 86 92 87 usbvendors = [] 93 88 usbproducts = [] … … 107 102 mode = 0 108 103 strg = "" 109 104 cstrg = "" 110 for ln in file(usbids, "r").readlines():105 for ln in open(usbids, "r", errors="ignore"): 111 106 if ln[0] == '#': 112 107 continue 113 108 ln = ln.rstrip('\n') … … 146 141 147 142 def bin_search(first, last, item, list): 148 143 "binary search on list, returns -1 on fail, match idx otherwise, recursive" 149 #print "bin_search(%i,%i)" % (first, last)150 144 if first == last: 151 145 return -1 152 146 if first == last-1: … … 233 227 for nm in devlst: 234 228 dir = prefix + usbname 235 229 prep = "" 236 #print nm237 230 idx = nm.find('/') 238 231 if idx != -1: 239 232 prep = nm[:idx+1] … … 404 397 try: 405 398 self.nointerfaces = int(readattr(fname, "bNumInterfaces")) 406 399 except: 407 #print "ERROR: %s/bNumInterfaces = %s" % (fname,408 # readattr(fname, "bNumInterfaces"))a409 400 self.nointerfaces = 0 410 401 try: 411 402 self.driver = readlink(fname, "driver") … … 421 412 for dirent in os.listdir(prefix + self.fname): 422 413 if not dirent[0:1].isdigit(): 423 414 continue 424 #print dirent425 415 if os.access(prefix + dirent + "/bInterfaceClass", os.R_OK): 426 416 iface = UsbInterface(self, self.level+1) 427 417 iface.read(dirent) … … 532 522 def read_usb(): 533 523 "Read toplevel USB entries and print" 534 524 for dirent in os.listdir(prefix): 535 #print dirent,536 525 if not dirent[0:3] == "usb": 537 526 continue 538 527 usbdev = UsbDevice(None, 0) … … 590 579 fix_usbclass() 591 580 except: 592 581 print(" WARNING: Failure to read usb.ids", file=sys.stderr) 593 #print >>sys.stderr, sys.exc_info()594 582 read_usb() 595 583 596 584 # Entry point