File: lsusb.py

package info (click to toggle)
linux-minidisc 0.9.16-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,640 kB
  • sloc: ansic: 6,389; cpp: 2,731; python: 2,537; perl: 866; sh: 207; makefile: 10
file content (31 lines) | stat: -rwxr-xr-x 740 bytes parent folder | download | duplicates (5)
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()