-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_manpage
executable file
·59 lines (50 loc) · 1.59 KB
/
update_manpage
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 = "egt"
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,
)