File: generate_udev_docs.py

package info (click to toggle)
libnitrokey 3.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 900 kB
  • sloc: cpp: 6,246; python: 2,095; ansic: 255; makefile: 59; sh: 57
file content (33 lines) | stat: -rwxr-xr-x 857 bytes parent folder | download
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
32
33
import click
import regex as re


@click.command()
@click.argument('input', type=click.File('rt'))
def main(input: click.File):
    print(f"| {'Name':40s} | {'USB ID':9s} |")
    print("|------------------------------------------|:---------:|")
    name = ''
    res = []
    for l in input:
        l = l.strip()
        if l.startswith("#"):
            name = l.strip("#").strip()
            continue
        pid = re.findall(r'ATTR[S]?\{idProduct\}=="(\w+)"', l, re.VERSION1)
        vid = re.findall(r'ATTR[S]?\{idVendor\}=="(\w+)"', l, re.VERSION1)
        if pid:
            res.append((name, vid[0], pid[0]))

    res = sorted(res)
    for r in res:
        if "dev Entry" in r[0]:
            continue
        print(f"| {r[0]:40s} | {r[1]}:{r[2]} |")

    print()
    print(f'Generated from {input.name}')


if __name__ == '__main__':
    main()