Skip to content

Commit a0e5010

Browse files
committed
switch update.cgi to python
1 parent fdb1f5d commit a0e5010

File tree

1 file changed

+60
-32
lines changed

1 file changed

+60
-32
lines changed

book/update.cgi

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,60 @@
1-
#!/usr/bin/perl
2-
3-
use strict;
4-
use warnings;
5-
6-
use CGI;
7-
my $r = new CGI;
8-
9-
print $r->header();
10-
print "<p>pulling repo...<br/>";
11-
system 'git fetch origin && git reset --hard origin/master';
12-
system 'git submodule update --init --recursive';
13-
print "<br/>done.</p>";
14-
15-
print "<p>building documentation...<br/>";
16-
chdir "..";
17-
18-
my $status = system('/bin/bash', '-c', '
19-
source venv/bin/activate &&
20-
poetry install --only docs &&
21-
sphinx-build -M html underactuated /tmp/underactuated_doc &&
22-
rm -rf book/python &&
23-
cp -r /tmp/underactuated_doc/html book/python
24-
');
25-
26-
if ($status == 0) {
27-
print "<br/>done.</p>";
28-
} else {
29-
print "<br/>Error occurred: $status</p>";
30-
}
31-
32-
print $r->end_html;
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import subprocess
5+
6+
try:
7+
# Do all work first
8+
git_output = subprocess.run(
9+
["git", "fetch", "origin"], capture_output=True, text=True, check=True
10+
).stdout
11+
12+
git_output += subprocess.run(
13+
["git", "reset", "--hard", "origin/master"],
14+
capture_output=True,
15+
text=True,
16+
check=True,
17+
).stdout
18+
19+
git_output += subprocess.run(
20+
["git", "submodule", "update", "--init", "--recursive"],
21+
capture_output=True,
22+
text=True,
23+
check=True,
24+
).stdout
25+
26+
os.chdir("..")
27+
28+
build_output = subprocess.run(
29+
[
30+
"/bin/bash",
31+
"-c",
32+
"source venv/bin/activate && "
33+
"poetry install --only docs && "
34+
"echo 'Contents of /tmp before:' && ls -la /tmp && "
35+
"sphinx-build -M html underactuated /tmp/underactuated_doc && "
36+
"echo 'Contents of /tmp after:' && ls -la /tmp && "
37+
"rm -rf book/python && "
38+
"cp -r /tmp/underactuated_doc/html book/python",
39+
],
40+
capture_output=True,
41+
text=True,
42+
check=True,
43+
).stdout
44+
45+
# Now we can safely print headers and content
46+
print("Content-Type: text/html\n")
47+
print("<html><body>")
48+
print("<p>pulling repo...</p>")
49+
print(f"<pre>{git_output}</pre>")
50+
print("<p>done.</p>")
51+
print("<p>building documentation...</p>")
52+
print(f"<pre>{build_output}</pre>")
53+
print("<p>done.</p>")
54+
print("</body></html>")
55+
56+
except Exception as e:
57+
print("Content-Type: text/html\n")
58+
print("<html><body>")
59+
print(f"<p>Error: {str(e)}</p>")
60+
print("</body></html>")

0 commit comments

Comments
 (0)