- Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathupdate_html.py
74 lines (62 loc) · 2.54 KB
/
update_html.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
importos, sys
importglob
deffind_index_path(index_file):
withopen(index_file, "r") asf:
lines=f.readlines()
forlineinlines:
pos=line.find('index.html" class="icon icon-home"')
ifpos<0:
continue
pos1=line.rfind("\"", 0, pos)
ifpos1<0:
return""
else:
return"../"+line[pos1+1: pos]
return"ignore"
defupdate_version_link(version, folder_name, index_file):
index_buf=""
index_path=find_index_path(index_file)
ifindex_path=='ignore':
return
withopen(index_file, "r") asf:
index_buf=f.read()
key_str=' <div class="version">\n {}\n </div>'.format(version)
version_list='''<div class="version">
<a href="{}versions.html">{}▼</a>
<p>Click link above to switch version</p>
</div>'''.format(index_path, folder_name)
index_buf=index_buf.replace(key_str, version_list)
withopen(index_file, "w") asf:
f.write(index_buf)
defupdate_search(folder):
search_file_name="{}/search.html".format(folder)
withopen(search_file_name, "r") asf:
index_buf=f.read()
key_str='<script src="_static/searchtools.js"></script>'
version_list='''<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=fc837d61"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
<script src="_static/searchtools.js"></script>'''
index_buf=index_buf.replace(key_str, version_list)
withopen(search_file_name, "w") asf:
f.write(index_buf)
defmain(folder, version):
folder_name=os.path.basename(folder)
forindex_fileinglob.glob('{}/**/*.html'.format(folder),recursive=True):
update_version_link(version, folder_name, index_file)
update_search(folder)
defhelp(me):
print("python {} html_folder version".format(me))
if__name__=="__main__":
iflen(sys.argv)<3:
help(sys.argv[0])
sys.exit(1)
folder=sys.argv[1]
version=sys.argv[2]
main(folder, version)