forked from clalancette/pycdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-pydoc.py
executable file
·38 lines (30 loc) · 1.06 KB
/
custom-pydoc.py
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
#!/usr/bin/python3
try:
from cStringIO import StringIO as BytesIO
except ImportError:
from io import BytesIO
import pydoc
import lxml.etree
html = pydoc.HTMLDoc()
# Generate the documentation from the pydoc strings
object, name = pydoc.resolve('pycdlib.pycdlib', 0)
page = html.page(pydoc.describe(object), html.document(object, name))
# Now parse that documentation
parser = lxml.etree.HTMLParser()
tree = lxml.etree.parse(BytesIO(page.encode('ascii')), parser)
# Now we remove the "Modules" section, since it contains only links to parts
# of the API that we are not documenting
doc = tree.getroot()
tables = doc.xpath('/html/body/table')
remove_table = None
for table in tables:
for tr in table.xpath('tr'):
bgcolor = tr.get('bgcolor')
if bgcolor == '#aa55cc':
# We found the 'Modules' section; go back up to the table to remove it
remove_table = table
break
if remove_table is not None:
remove_table.getparent().remove(remove_table)
# Print out the results
print(lxml.etree.tostring(doc).decode('ascii'))