forked from malthejorgensen/CHAOS-API-Documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_docs.py
77 lines (59 loc) · 2 KB
/
create_docs.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
75
76
import json
import os
import argparse
from datetime import datetime
from shutil import rmtree, move
from sh import git, Command
parser = argparse.ArgumentParser()
parser.add_argument('--stash', action='store_true', help='Stash before changing to gh-pages')
parser.add_argument('--commit', action='store_true', help='Whether the auto-generated docs should be committed')
parser.add_argument('--push-gh-pages', help='Specify a repository on which to create Github Pages')
args = parser.parse_args()
versions = json.load(open('versions.json'))
dir_names = []
try:
rmtree('tmp')
except:
pass
os.makedirs('tmp')
sphinx_build = Command('sphinx-build')
if args.stash:
git.stash()
for name, options in versions.items():
print 'Generating docs for version ' + name
try:
git.checkout(options['branch_name'])
print 'Checked out "' + options['branch_name'] + '"'
# Print latest commit
print git('--no-pager', 'log', '-1')
os.environ['CHAOS_DOC_VERSION'] = name
sphinx_build('-b', 'html', '-a', '-E', 'source', 'tmp/' + options['directory_name'])
del os.environ['CHAOS_DOC_VERSION']
dir_names.append(options['directory_name'])
except:
raise
print 'Could not check out branch "' + options['branch_name'] + '".'
exit()
time_str = datetime.now().strftime('%Y-%m-%d %H:%M:%S %z')
try:
git.checkout('gh-pages')
for dir_name in dir_names:
# Remove the current documentation folders (v4, v5, current)
try:
rmtree(dir_name)
except:
pass
# Move generated folders (in 'tmp/') into the root folder
move('tmp/' + dir_name, '.')
# Remove 'tmp/'
rmtree('tmp')
except:
raise
if args.commit or args.push_gh_pages:
# Commit new version
git.add(dir_names)
git.commit(m='Auto-generated docs %s' % time_str)
if args.push_gh_pages:
# Commit new version
print 'Pushing to "%s"' % args.push_gh_pages
git.push([args.push_gh_pages, 'gh-pages'])