-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathgen_command_docs.py
More file actions
71 lines (52 loc) · 1.58 KB
/
gen_command_docs.py
File metadata and controls
71 lines (52 loc) · 1.58 KB
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
import sys
import os
import fnmatch
import re
sys.path.insert(0, 'doc-source/mock')
sys.path.insert(0, 'mock')
import gdb
header = \
"""
Command Reference
=================
.. toctree::
:titlesonly:
"""
def gen_command_docs(root: str) -> None:
modules = list()
print("*** Generating command docs")
regex = re.compile(fnmatch.translate("[a-z]*.py"))
for _root, dirs, files in os.walk(f"{root}/../crash/commands"):
if '__pycache__' in _root:
continue
for filename in files:
path = os.path.join(_root, filename)
if regex.match(filename):
mod = filename.replace(".py", "")
modules.append(f"crash.commands.{mod}")
old = set()
try:
os.mkdir(f"{root}/commands")
except FileExistsError:
pass
print(f"Writing {root}/commands/commands.rst")
cmdtoc = open(f"{root}/commands/commands.rst", "w")
print(header, file=cmdtoc)
print(f"** Generating docs for {modules}")
for mod in modules:
__import__(mod)
new = set(gdb.commands)
commands = new - old
for command in commands:
f = open(f"{root}/commands/{command}.rst", "w")
print(f"``{command}``", file=f)
print(f"----------------", file=f)
print(f".. automodule:: {mod}", file=f)
f.close()
old = new
for command in sorted(gdb.commands):
print(f" {command}", file=cmdtoc)
cmdtoc.close()