File: update-manpage

package info (click to toggle)
staticsite 2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 14,648 kB
  • sloc: javascript: 33,722; python: 9,851; makefile: 46; sh: 4
file content (59 lines) | stat: -rwxr-xr-x 1,630 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python3

import re
import shutil
import sys
import subprocess
import tempfile

COMMAND = "ssite"
SECTION = 1

res = subprocess.run([sys.executable, "setup.py", "--version"], stdout=subprocess.PIPE, text=True, check=True)
version = res.stdout.strip()

res = subprocess.run([sys.executable, COMMAND, "--help"], stdout=subprocess.PIPE, text=True, check=True)
subcommands = re.sub(r"^.+\{(.+)\}.+$", r"\1", res.stdout, flags=re.DOTALL).split(",")

with tempfile.NamedTemporaryFile("wt") as tf:
    print("[>DESCRIPTION]", file=tf)

    for subcommand in subcommands:
        res = subprocess.run(
            [
                "help2man",
                "--name=" + COMMAND,
                f"--section={SECTION}",
                "--no-info",
                "--version-string=dummy",
                f"./{COMMAND} {subcommand}",
            ],
            stdout=subprocess.PIPE,
            text=True,
            check=True,
        )
        subcommand_doc = re.sub(r"^.+.SH DESCRIPTION", "", res.stdout, flags=re.DOTALL)
        print(".SH ", subcommand.upper(), " SUBCOMMAND", file=tf)
        tf.write(subcommand_doc)

    try:
        with open(f"{COMMAND}.1.in", "rt") as fd:
            shutil.copyfileobj(fd, tf)
    except FileNotFoundError:
        pass

    tf.flush()

    subprocess.run(
        [
            "help2man",
            f"--include={tf.name}",
            f"--name={COMMAND}",
            f"--section={SECTION}",
            "--no-info",
            f"--version-string={version}",
            f"--output={COMMAND}.{SECTION}",
            f"./{COMMAND}",
        ],
        check=True,
    )