File: build_manpage.py

package info (click to toggle)
bleak 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,708 kB
  • sloc: python: 10,382; makefile: 165; java: 105
file content (75 lines) | stat: -rwxr-xr-x 1,661 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python3

import subprocess
import tempfile
import os


def parse_autoflake_py() -> tuple[str, list[str]]:
    lines: list[str] = []
    for line in open("bleak/__init__.py"):
        if lines:
            if lines and "parser.parse_args" in line:
                break
            lines.append(line)
            continue

        if "argparse.ArgumentParser" in line:
            lines.append(line)
            continue

    return lines


def argparse_pyfile():
    lines = parse_autoflake_py()
    return f"""
import argparse

def get_argparse():
{"".join(lines)}
    return parser
"""


def get_argparse_manpage_cmd(filename):
    return [
        "argparse-manpage",
        "--pyfile",
        filename,
        "--function",
        "get_argparse",
        "--author",
        "Henrik Blidh",
        "--author-email",
        "henrik.blidh@nedomkull.com",
        "--project-name",
        "bleak",
        "--url",
        "https://github.com/hbldh/bleak",
    ]


def run_argparse_manpage():
    with tempfile.TemporaryDirectory() as dir_tmp:
        filename = os.path.join(dir_tmp, "bleak")
        tmp = open(filename, "w")
        tmp.write(argparse_pyfile())
        tmp.flush()
        cmd = get_argparse_manpage_cmd(filename)
        p = subprocess.run(cmd, text=True, capture_output=True)
        os.remove(filename)
        return p.stdout.splitlines()


def build_manpage():
    manpage = run_argparse_manpage()
    for line in manpage:
        if line == "bleak":
            print("bleak \- Bluetooth Low Energy platform agnostic client")
            continue
        print(line)


if __name__ == "__main__":
    build_manpage()