comparison python/utils/lsusb.py @ 292:534b94b40aa8

Fixup reorganize
author Windel Bouwman
date Wed, 27 Nov 2013 08:06:42 +0100
parents python/lsusb.py@654093a9a1e3
children
comparison
equal deleted inserted replaced
290:7b38782ed496 292:534b94b40aa8
1 #!/usr/bin/python
2
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))
27
28 context = UsbContext()
29 for d in context.DeviceList:
30 print(d)
31