annotate python/lsusb.py @ 153:e05b2b216bfc

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