-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_manpage
executable file
·36 lines (28 loc) · 1.28 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
#!/usr/bin/python3
import re
import shutil
import sys
import subprocess
import tempfile
res = subprocess.run([sys.executable, "setup.py", "--version"], stdout=subprocess.PIPE, text=True, check=True)
version = res.stdout.strip()
res = subprocess.run([sys.executable, "arkimaps", "--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=arkimaps", "--section=1",
"--no-info", "--version-string=dummy", f"./arkimaps {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)
with open("arkimaps.1.in", "rt") as fd:
shutil.copyfileobj(fd, tf)
tf.flush()
subprocess.run(
["help2man", f"--include={tf.name}", "--name=arkimaps",
"--section=1", "--no-info", f"--version-string={version}",
"--output=arkimaps.1", "./arkimaps"],
check=True)