forked from sxrsdk/sxrsdk-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.py
215 lines (162 loc) · 6.76 KB
/
publish.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python
import os
import shutil
import subprocess
import glob
import argparse
def get_curr_path():
return os.path.dirname(os.path.realpath(__file__))
def which(program):
def is_exe(cmd_path):
return os.path.exists(cmd_path) and os.access(cmd_path, os.X_OK)
def ext_candidates(cmd_path):
yield cmd_path
for ext in os.environ.get("PATHEXT", "").split(os.pathsep):
yield cmd_path + ext
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
for candidate in ext_candidates(exe_file):
if is_exe(candidate):
return candidate
return None
def copy_all(src, dst):
for filename in glob.glob(os.path.join(src, '*.*')):
shutil.copy(filename, dst)
def copy_tree(src, dst):
if os.path.isdir(src):
shutil.copytree(src, dst)
elif os.path.exists(src):
shutil.copy(src, dst)
def del_tree(path):
if os.path.isdir(path):
shutil.rmtree(path)
elif os.path.isfile(path):
os.remove(path)
else:
print 'Invalid path: ' + path
def update_version(file_path, version_num):
fh = open(file_path, 'r')
html_content = fh.read()
from string import Template
s = Template(html_content)
replaced_content = s.substitute(sxr_version=version_num)
fh = open(file_path, 'w')
fh.write(replaced_content)
fh.close()
def gen_javadoc(src_path, out_path, package_name):
cmd = ['javadoc', '-Xdoclint:none']
cmd.extend(['-d', out_path])
cmd.extend(['-sourcepath', src_path])
cmd.extend(['-subpackages', package_name])
cmd.extend(['-encoding', 'UTF-8'])
cmd.extend(['-charset', 'UTF-8'])
cmd.append('-quiet')
subprocess.call(cmd)
def update_template(out_path, version_num):
curr_path = get_curr_path()
full_out_path = os.path.join(curr_path, out_path)
version_out_path = os.path.join(full_out_path, version_num)
index2_path = os.path.join(full_out_path, 'index2.html')
update_version(index2_path, version_num)
java_doc_index_path = os.path.join(version_out_path, 'index.html')
update_version(java_doc_index_path, version_num)
def gen_java_docs(base_path, out_path):
del_tree(out_path)
# Generate frameworks
sub_out_path = os.path.join(out_path, 'Framework')
src_path = os.path.join(base_path, 'SXR', 'Framework', 'framework', 'src', 'main', 'java')
gen_javadoc(src_path, sub_out_path, 'org.gearvrf')
# Generate 3DCursor
sub_out_path = os.path.join(out_path, '3DCursor')
src_path = os.path.join(base_path, 'SXR', 'Extensions', '3DCursor', '3DCursorLibrary', 'src', 'main', 'java')
gen_javadoc(src_path, sub_out_path, 'org.gearvrf')
# Generate DebugWebServer
sub_out_path = os.path.join(out_path, 'DebugWebServer')
src_path = os.path.join(base_path, 'SXR', 'Extensions', 'DebugWebServer', 'debugwebserver', 'src', 'main', 'java')
gen_javadoc(src_path, sub_out_path, 'smcl.samsung')
# Generate SceneSerializer
sub_out_path = os.path.join(out_path, 'SceneSerializer')
src_path = os.path.join(base_path, 'SXR', 'Extensions', 'SceneSerializer', 'sceneserializer', 'src', 'main', 'java')
gen_javadoc(src_path, sub_out_path, 'org.gearvrf')
# Generate WidgetPlugin
sub_out_path = os.path.join(out_path, 'WidgetPlugin')
src_path = os.path.join(base_path, 'SXR', 'Extensions', 'WidgetPlugin', 'widgetplugin', 'src', 'main', 'java')
gen_javadoc(src_path, sub_out_path, 'org.gearvrf')
# Generate sxr-physics
sub_out_path = os.path.join(out_path, 'sxr-physics')
src_path = os.path.join(base_path, 'SXR', 'Extensions', 'sxr-physics', 'src', 'main', 'java')
gen_javadoc(src_path, sub_out_path, 'org.gearvrf')
# Generate particle system
sub_out_path = os.path.join(out_path, 'sxr-particlesystem')
src_path = os.path.join(base_path, 'SXR', 'Extensions', 'sxr-particlesystem', 'src', 'main', 'java')
gen_javadoc(src_path, sub_out_path, 'org.gearvrf')
def gen_all_docs(out_path, api_template_path, version_num):
# Check required commands
javadoc_path = which('javadoc')
if javadoc_path is None:
print '==> Error: Failed to find javadoc, please check your java setup'
return
mkdocs_path = which('mkdocs')
if mkdocs_path is None:
print '==> Error: Failed to find mkdocs, please follow the Readme to set it up'
return
del_tree(out_path)
copy_tree(api_template_path, out_path)
# Search for SXR folder
# Search for SXR_SOURCE_PATH
sxr_path = os.environ.get('SXR_SOURCE_PATH')
curr_path = get_curr_path()
full_out_path = os.path.join(curr_path, out_path, version_num)
template_path = os.path.join(curr_path, api_template_path, 'template')
print "==> Setting up environment"
if sxr_path is None:
# Search at the parent dir
parent_path = os.path.dirname(curr_path)
sxr_path = os.path.join(parent_path, 'sxrsdk')
# Generate all java docs
print '==> generate javadoc'
if os.path.isdir(sxr_path):
gen_java_docs(sxr_path, full_out_path)
else:
print "==> Invalid SXR path: " + sxr_path
# copy template
print '==> copy template'
copy_all(template_path, full_out_path)
# Update versions in template
update_template(out_path, version_num)
def main():
parser = argparse.ArgumentParser(description='Generate the documentation site for the Samsung XR SDK')
parser.add_argument('-v', metavar='Version', dest='version', help='specify SXR SDK version', default='v3.3')
parser.add_argument('-deploy', metavar='Deploy', dest='deploy', help='specify deploy target: github')
args = parser.parse_args()
if not args.version.startswith('v'):
args.version = 'v' + args.version
print '=> SXR SDK version: ' + args.version
# Generate site with mkdocs
from subprocess import call
call(['mkdocs', 'build'])
print '=> Generating Documentation site'
# Generate API reference from SXR SDK source
print '=> Generating API reference site'
gen_all_docs('temp', 'api_reference', args.version)
# Copy api_reference and replace the placeholder api_reference in site
print '=> Merging API reference with documentation'
if os.path.isdir('site'):
del_tree('site/api_reference')
copy_tree('temp', 'site/api_reference')
print '==> Add API reference'
else:
print '=> Error: Failed to find site directory please make sure mkdocs is setup correctly'
return
if args.deploy == 'github':
print '=> Deploy to github'
from deploy import gh_deploy
gh_deploy()
if __name__ == "__main__":
# main()
main()