Signed-off-by: Mantas Mikulėnas <grawity@xxxxxxxxx> --- lsusb.py.in | 77 +++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/lsusb.py.in b/lsusb.py.in index eb00211..5720cd2 100644 --- a/lsusb.py.in +++ b/lsusb.py.in @@ -236,6 +236,7 @@ class UsbEndpoint: self.parent = parent self.level = level self.fname = fname + self.path = "" self.epaddr = 0 self.len = 0 self.ival = "" @@ -246,18 +247,16 @@ class UsbEndpoint: self.read(self.fname) def read(self, fname): - fullpath = "" - if self.parent: - fullpath = self.parent.fullpath + "/" - fullpath += fname - self.epaddr = int(readattr(fullpath, "bEndpointAddress"), 16) - ival = int(readattr(fullpath, "bInterval"), 16) + self.fname = fname + self.path = self.parent.path + "/" + fname + self.epaddr = int(readattr(self.path, "bEndpointAddress"), 16) + ival = int(readattr(self.path, "bInterval"), 16) if ival: - self.ival = "(%s)" % readattr(fullpath, "interval") - self.len = int(readattr(fullpath, "bLength"), 16) - self.type = readattr(fullpath, "type") - self.attr = int(readattr(fullpath, "bmAttributes"), 16) - self.max = int(readattr(fullpath, "wMaxPacketSize"), 16) + self.ival = "(%s)" % readattr(self.path, "interval") + self.len = int(readattr(self.path, "bLength"), 16) + self.type = readattr(self.path, "type") + self.attr = int(readattr(self.path, "bmAttributes"), 16) + self.max = int(readattr(self.path, "wMaxPacketSize"), 16) def __str__(self): indent = self.level + len(self.parent.fname) @@ -271,8 +270,8 @@ class UsbInterface: def __init__(self, parent, fname, level=1): self.parent = parent self.level = level - self.fullpath = "" self.fname = fname + self.path = "" self.iclass = 0 self.isclass = 0 self.iproto = 0 @@ -285,24 +284,20 @@ class UsbInterface: self.read(self.fname) def read(self, fname): - fullpath = "" - if self.parent: - fullpath += self.parent.fname + "/" - fullpath += fname - self.fullpath = fullpath self.fname = fname - self.iclass = int(readattr(fullpath, "bInterfaceClass"),16) - self.isclass = int(readattr(fullpath, "bInterfaceSubClass"),16) - self.iproto = int(readattr(fullpath, "bInterfaceProtocol"),16) - self.noep = int(readattr(fullpath, "bNumEndpoints")) + self.path = self.parent.path + "/" + fname + self.iclass = int(readattr(self.path, "bInterfaceClass"),16) + self.isclass = int(readattr(self.path, "bInterfaceSubClass"),16) + self.iproto = int(readattr(self.path, "bInterfaceProtocol"),16) + self.noep = int(readattr(self.path, "bNumEndpoints")) try: - self.driver = readlink(fname, "driver") - self.devname = find_dev(self.driver, fname) + self.driver = readlink(self.path, "driver") + self.devname = find_dev(self.driver, self.path) except: pass self.protoname = find_usb_class(self.iclass, self.isclass, self.iproto) if showeps: - for dirent in os.listdir(prefix + fullpath): + for dirent in os.listdir(prefix + self.path): if dirent.startswith("ep_"): ep = UsbEndpoint(self, dirent, self.level+1) self.eps.append(ep) @@ -326,7 +321,7 @@ class UsbDevice: self.parent = parent self.level = level self.fname = fname - self.fullpath = "" + self.path = "" self.iclass = 0 self.isclass = 0 self.iproto = 0 @@ -348,15 +343,15 @@ class UsbDevice: def read(self, fname): self.fname = fname - self.fullpath = fname - self.iclass = int(readattr(fname, "bDeviceClass"), 16) - self.isclass = int(readattr(fname, "bDeviceSubClass"), 16) - self.iproto = int(readattr(fname, "bDeviceProtocol"), 16) - self.vid = int(readattr(fname, "idVendor"), 16) - self.pid = int(readattr(fname, "idProduct"), 16) + self.path = fname + self.iclass = int(readattr(self.path, "bDeviceClass"), 16) + self.isclass = int(readattr(self.path, "bDeviceSubClass"), 16) + self.iproto = int(readattr(self.path, "bDeviceProtocol"), 16) + self.vid = int(readattr(self.path, "idVendor"), 16) + self.pid = int(readattr(self.path, "idProduct"), 16) try: - self.name = readattr(fname, "manufacturer") + " " \ - + readattr(fname, "product") + self.name = readattr(self.path, "manufacturer") + " " \ + + readattr(self.path, "product") except: pass if self.name: @@ -372,23 +367,23 @@ class UsbDevice: if not self.name: self.name = oldnm try: - ser = readattr(fname, "serial") + ser = readattr(self.path, "serial") # Some USB devs report "serial" as serial no. suppress if (ser and ser != "serial"): self.name += " " + ser except: pass - self.usbver = readattr(fname, "version") - self.speed = readattr(fname, "speed") - self.maxpower = readattr(fname, "bMaxPower") - self.noports = int(readattr(fname, "maxchild")) + self.usbver = readattr(self.path, "version") + self.speed = readattr(self.path, "speed") + self.maxpower = readattr(self.path, "bMaxPower") + self.noports = int(readattr(self.path, "maxchild")) try: - self.nointerfaces = int(readattr(fname, "bNumInterfaces")) + self.nointerfaces = int(readattr(self.path, "bNumInterfaces")) except: self.nointerfaces = 0 try: - self.driver = readlink(fname, "driver") - self.devname = find_dev(self.driver, fname) + self.driver = readlink(self.path, "driver") + self.devname = find_dev(self.driver, self.path) except: pass -- 2.21.0