diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/utils/lsusb.py	Wed Nov 27 08:06:42 2013 +0100
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+from usb import UsbContext
+
+# try to read usb.ids:
+vids = {}
+pids = {}
+try:
+   with open('usb.ids', 'r', errors='ignore') as f:
+      vid = 0
+      for l in f:
+         if l.startswith('#') or not l.strip():
+            continue
+         if l.startswith('\t\t'):
+            print('iface:', l)
+         elif l.startswith('\t'):
+            print('product', l)
+            pid = int(l[1:5], 16)
+            print('product', hex(pid), l)
+         else:
+            print('vendor', l)
+            vid = int(l[0:4], 16)
+            print('vendor', hex(vid), l)
+
+except IOError as e:
+   print("Error loading usb id's: {0}".format(e))
+
+context = UsbContext()
+for d in context.DeviceList:
+   print(d)
+