comparison python/lsusb.py @ 130:654093a9a1e3

Added icons, improved device explorer
author Windel Bouwman
date Sat, 19 Jan 2013 18:16:04 +0100
parents 056face59ee7
children
comparison
equal deleted inserted replaced
129:9e350a7dde98 130:654093a9a1e3
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 from usb import UsbContext 3 from usb import UsbContext
4
5 # try to read usb.ids:
6 vids = {}
7 pids = {}
8 try:
9 with open('usb.ids', 'r', errors='ignore') as f:
10 vid = 0
11 for l in f:
12 if l.startswith('#') or not l.strip():
13 continue
14 if l.startswith('\t\t'):
15 print('iface:', l)
16 elif l.startswith('\t'):
17 print('product', l)
18 pid = int(l[1:5], 16)
19 print('product', hex(pid), l)
20 else:
21 print('vendor', l)
22 vid = int(l[0:4], 16)
23 print('vendor', hex(vid), l)
24
25 except IOError as e:
26 print("Error loading usb id's: {0}".format(e))
4 27
5 context = UsbContext() 28 context = UsbContext()
6 for d in context.DeviceList: 29 for d in context.DeviceList:
7 print(d) 30 print(d)
8 31