File: lsusb.py

package info (click to toggle)
linux-minidisc 0.9.13-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,096 kB
  • ctags: 1,530
  • sloc: ansic: 6,345; cpp: 2,569; python: 2,451; perl: 866; sh: 22; makefile: 8
file content (31 lines) | stat: -rwxr-xr-x 740 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
import usb1
import sys

def main():
    verbose = False
    filter_set = set()

    for arg in sys.argv:
        if arg == '-v':
            verbose = True
        elif ':' in arg:
            vendor, product = arg.split(':')
            filter_set.add((int(vendor, 16), int(product, 16)))

    if len(filter_set):
        def test(device):
            return (device.getVendorID(), device.getProductID()) in filter_set
    else:
        def test(device):
            return True
    context = usb1.LibUSBContext()
    for device in context.getDeviceList():
        if test(device):
            print device
            if verbose:
                print device.reprConfigurations()

if __name__ == '__main__':
    main()