diff --git a/book/update.cgi b/book/update.cgi index a6b078d4..baea8731 100755 --- a/book/update.cgi +++ b/book/update.cgi @@ -1,32 +1,57 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use CGI; -my $r = new CGI; - -print $r->header(); -print "

pulling repo...
"; -system 'git fetch origin && git reset --hard origin/master'; -system 'git submodule update --init --recursive'; -print "
done.

"; - -print "

building documentation...
"; -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 "
done.

"; -} else { - print "
Error occurred: $status

"; -} - -print $r->end_html; +#!/usr/bin/env python3 + +import os +import subprocess + +try: + 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("..") + + build_output = subprocess.run( + [ + "/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", + ], + capture_output=True, + text=True, + check=True, + ).stdout + + # Now we can safely print headers and content + print("Content-Type: text/html\n") + print("") + print("

pulling repo...

") + print(f"
{git_output}
") + print("

done.

") + print("

building documentation...

") + print(f"
{build_output}
") + print("

done.

") + print("") + +except Exception as e: + print("Content-Type: text/html\n") + print("") + print(f"

Error: {str(e)}

") + print("")