-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_docs.py
140 lines (106 loc) · 4.58 KB
/
gen_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
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
#!/usr/bin/python3
import subprocess
import shlex
import shutil
import json
import datetime
index='''
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="fluid_style.css">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Lato%3A300%2C300italic%2C400%2C400italic%2C700%2C700italic&display=swap">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-W8TXVP5YQW"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-W8TXVP5YQW'); </script>
<!-- update the version number as needed -->
<script defer src="/__/firebase/7.9.3/firebase-app.js"></script>
<!-- include only the Firebase features as you need -->
<script defer src="/__/firebase/7.9.3/firebase-auth.js"></script>
<script defer src="/__/firebase/7.9.3/firebase-database.js"></script>
<script defer src="/__/firebase/7.9.3/firebase-messaging.js"></script>
<script defer src="/__/firebase/7.9.3/firebase-storage.js"></script>
<!-- initialize the SDK after all desired features are loaded -->
<script defer src="/__/firebase/init.js"></script>
</head>
<body>
<div class="fluid_sidebar">
<h1><a href="https://www.oshackathon.com">OS Hackathon</a></h1>
</div>
<div class="fluid_header">
<h1>Portable GPU Programming Codelabs</h1>
<h2>Accelerate science on all platforms.</h2>
<h3><i>Supported by AMD & Fluid Numerics</i></h3>
</div>
<div class="fluid_body">
<h2><a href="https://www.oshackathon.com">Head back to OS Hackathon</a></h2>
[BODY]
</div>
<div class="fluid_footer">
<h2>Let us know if we can do anything to improve these codelabs!</h2>
<h3><a href="https://github.com/os-hackathon/amd-rocm-codelabs/issues/new">Submit your feedback here</a></h3>
</div>
</body>
</html>
'''
firebase_txt='''
<!-- update the version number as needed -->
<script defer src="/__/firebase/7.9.3/firebase-app.js"></script>
<!-- include only the Firebase features as you need -->
<script defer src="/__/firebase/7.9.3/firebase-auth.js"></script>
<script defer src="/__/firebase/7.9.3/firebase-database.js"></script>
<script defer src="/__/firebase/7.9.3/firebase-messaging.js"></script>
<script defer src="/__/firebase/7.9.3/firebase-storage.js"></script>
<!-- initialize the SDK after all desired features are loaded -->
<script defer src="/__/firebase/init.js"></script>
'''
def inject_firebase(subdirectory):
filepath = subdirectory+'/index.html'
cl_index = []
with open(filepath) as fp:
line = fp.readline()
cl_index.append(line)
cnt = 1
while line:
line = fp.readline()
cl_index.append(line)
if '</style>' in line:
cl_index.append(firebase_txt)
cnt += 1
f=open(filepath,'w')
f.write('\n'.join(cl_index))
f.close()
#END inject_firebase
def update_codelabs():
with open('./docs.json') as f:
config = json.load(f)
# Update tutorials
for tutorial in config['docs']:
print('Updating {}'.format(tutorial['title']))
subprocess.check_call(shlex.split('mkdir -p public/{}'.format(tutorial['subdirectory'])))
subprocess.check_call(shlex.split('./tools/claat/claat-linux-amd64 export {}'.format(tutorial['gdoc_id'])))
subprocess.check_call(shlex.split('rm -rf public/{}'.format(tutorial['subdirectory'])))
shutil.copytree('URL/', 'public/{}'.format(tutorial['subdirectory']))
inject_firebase('public/{}'.format(tutorial['subdirectory']))
subprocess.check_call(shlex.split('rm -rf URL/'.format(tutorial['subdirectory'])))
#END update_codelabs
def update_index():
with open('./docs.json') as f:
config = json.load(f)
timeStamp = datetime.datetime.now().strftime("%Y-%m-%d")
indexBody = '<p><i>Last Updated : {}</i></p> <br> <hr> <br>\n'.format(timeStamp)
# Update tutorials
for tutorial in config['docs']:
indexBody += '<h2><a href="./{SUBDIR}/index.html">{TITLE}</a></h2> \n '.format(SUBDIR=tutorial['subdirectory'],
TITLE=tutorial['title'])
indexBody += '<p>{DESCRIPTION}</p><br> <hr> <br>\n'.format(DESCRIPTION=tutorial['description'])
mainPageIndex = index.replace('[BODY]',indexBody)
f = open('public/index.html','w')
f.write(mainPageIndex)
f.close()
#END upate_index
def main():
update_index()
update_codelabs()
#END main
if __name__ == '__main__':
main()