Skip to content

Commit

Permalink
switch update.cgi to python
Browse files Browse the repository at this point in the history
  • Loading branch information
RussTedrake committed Jan 24, 2025
1 parent fdb1f5d commit 6271ba0
Showing 1 changed file with 59 additions and 32 deletions.
91 changes: 59 additions & 32 deletions book/update.cgi
Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
#!/usr/bin/perl

use strict;
use warnings;

use CGI;
my $r = new CGI;

print $r->header();
print "<p>pulling repo...<br/>";
system 'git fetch origin && git reset --hard origin/master';
system 'git submodule update --init --recursive';
print "<br/>done.</p>";

print "<p>building documentation...<br/>";
chdir "..";

my $status = system('/bin/bash', '-c', '
source venv/bin/activate &&
poetry install --only docs &&
sphinx-build -M html underactuated /tmp/underactuated_doc &&
rm -rf book/python &&
cp -r /tmp/underactuated_doc/html book/python
');

if ($status == 0) {
print "<br/>done.</p>";
} else {
print "<br/>Error occurred: $status</p>";
}

print $r->end_html;
#!/usr/bin/env python3

import os
import subprocess

try:
# Do all work first
git_output = subprocess.run(
["git", "fetch", "origin"], capture_output=True, text=True, check=True
).stdout

git_output += subprocess.run(
["git", "reset", "--hard", "origin/master"],
capture_output=True,
text=True,
check=True,
).stdout

git_output += subprocess.run(
["git", "submodule", "update", "--init", "--recursive"],
capture_output=True,
text=True,
check=True,
).stdout

os.chdir("..")

# Start the build process in background using the exact same command that worked before
with open("/tmp/underactuated_build_docs.log", "w") as log_file:
build_process = subprocess.Popen(
[
"/bin/bash",
"-c",
"source venv/bin/activate && "
"poetry install --only docs && "
"sphinx-build -M html underactuated /tmp/underactuated_doc && "
"rm -rf book/python && "
"cp -r /tmp/underactuated_doc/html book/python",
],
stdout=log_file,
stderr=subprocess.STDOUT, # Combine stderr with stdout
# start_new_session=True, # This is the only real change from the working version
)

# Now we can safely print headers and content
print("Content-Type: text/html\n")
print("<html><body>")
print("<p>pulling repo...</p>")
print(f"<pre>{git_output}</pre>")
print("<p>done.</p>")
print("<p>Documentation build started in the background.</p>")
print("<p>Check /tmp/underactuated_build_docs.log for progress.</p>")
print("</body></html>")

except Exception as e:
print("Content-Type: text/html\n")
print("<html><body>")
print(f"<p>Error: {str(e)}</p>")
print("</body></html>")

0 comments on commit 6271ba0

Please sign in to comment.