-
Notifications
You must be signed in to change notification settings - Fork 9
/
xgendoc.py
executable file
·71 lines (58 loc) · 2.12 KB
/
xgendoc.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
#!/usr/bin/python
# Copyright 2015 The Goga Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import subprocess
def Cmd(command, verbose=False, debug=False):
if debug:
print '=================================================='
print cmd
print '=================================================='
spr = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = spr.stdout.read()
err = spr.stderr.read().strip()
if verbose:
print out
print err
return out, err
odir = 'doc/'
idxfn = odir+'index.html'
licen = open('LICENSE', 'r').read()
def header(title):
return """<html>
<head>
<meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=utf-8\\">
<title>%s</title>
<link type=\\"text/css\\" rel=\\"stylesheet\\" href=\\"static/style.css\\">
<script type=\\"text/javascript\\" src=\\"static/godocs.js\\"></script>
<style type=\\"text/css\\"></style>
</head>
<body>
<div id=\\"page\\" class=\\wide\\">
<div class=\\"container\\">
""" % title
def footer():
return """
<div id=\\"footer\\">
<br /><br />
<hr>
<pre class=\\"copyright\\">
%s</pre><!-- copyright -->
</div><!-- footer -->
</div><!-- container -->
</div><!-- page -->
</body>
</html>""" % licen
Cmd('echo "'+header('Goga – Documentation')+'" > '+idxfn)
Cmd('echo "<h1>Goga – Documentation</h1>" >> '+idxfn)
Cmd('echo "<h2 id=\\"pkg-index\\">Index</h2>\n<div id=\\"manual-nav\\">\n<dl>" >> '+idxfn)
Cmd('godoc -html github.com/cpmech/goga >> '+idxfn)
# fix links
Cmd("sed -i -e 's@/src/target@https://github.com/cpmech/goga/blob/master/@g' "+idxfn+"")
Cmd("sed -i -e 's@/src/github.com/cpmech/goga/@https://github.com/cpmech/goga/blob/master/@g' "+idxfn+"")
# fix links to subdirectories (harder to automate)
subdirs = ["data", "doc", "examples"]
for subdir in subdirs:
Cmd("sed -i -e 's@<a href=\""+subdir+"/\">@<a href=\"https://github.com/cpmech/goga/tree/master/"+subdir+"\">@g' "+idxfn)
Cmd('echo "</dl>\n</div><!-- manual-nav -->" >> '+idxfn)
Cmd('echo "'+footer()+'" >> '+idxfn)