-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixdoc.py
executable file
·59 lines (42 loc) · 1.5 KB
/
fixdoc.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import os
import glob
import sys
import VirtualEnvOnDemand
if __name__ == '__main__':
VirtualEnvOnDemand.enableOnDemandImporter()
import AdvancedHTMLParser
VirtualEnvOnDemand.toggleOnDemandImporter(False)
if __name__ == '__main__':
# Ensure we are in the main package directory
myDir = os.path.dirname(__file__)
if myDir != '.':
os.chdir(myDir)
# Chdir to doc directory
failedToParse = {}
# import pdb; pdb.set_trace()
for fname in glob.glob('doc/*.html'):
if fname[4:] in ('index.html', 'exceptions.html'):
continue
try:
parser = AdvancedHTMLParser.AdvancedHTMLParser(fname)
except Exception as e:
failedToParse[fname] = e
continue
try:
badLink = parser.getElementsCustomFilter( lambda x : bool(x.getAttribute('href', '').startswith('file:/')))[0]
parent = badLink.parentNode
brNodeIdx = parent.children.index(badLink) - 1
indexLinkIdx = brNodeIdx - 1
brNode = parent.children[brNodeIdx]
indexLink = parent.children[indexLinkIdx]
parent.removeChild(badLink)
parent.removeChild(brNode)
indexLink.setAttribute('href', 'VirtualEnvOnDemand.html')
except Exception as e:
continue
# raise e
#sys.stderr.write('Got exception
#pass
with open(fname, 'wt') as f:
f.write(parser.getHTML())