forked from otanrikulu/Rdatasets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs2rst.py
36 lines (30 loc) · 1.13 KB
/
docs2rst.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
"""
Converts the HTML docs to human-readable rST and places them in a rst folder
in the doc/package folders.
Depends on pandoc being installed. Pandoc is available in repositories.
"""
import subprocess
import os
# directory names to skip
blacklisted = [".git", "license", "csv" ]
def html2rst(html):
p = subprocess.Popen(['pandoc', '--from=html', '--to=rst'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
return p.communicate(html)[0]
for root, dirnames, filenames in os.walk("./doc"):
for dir_name in dirnames:
if dir_name == "rst": # stay high level
continue
dest_dir = os.path.join(root, dir_name, "rst")
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
html_files = os.listdir(os.path.join(root, dir_name))
for f in html_files:
if f == 'rst':
continue
fin = os.path.join(root, dir_name, f)
fout = os.path.join(dest_dir, f.replace('html', 'rst'))
rst = html2rst(open(fin, 'r').read())
fout = open(fout, 'w')
fout.write(rst)
fout.close()