|
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 | + git_output = subprocess.run( |
| 8 | + ["git", "fetch", "origin"], capture_output=True, text=True, check=True |
| 9 | + ).stdout |
| 10 | + |
| 11 | + git_output += subprocess.run( |
| 12 | + ["git", "reset", "--hard", "origin/master"], |
| 13 | + capture_output=True, |
| 14 | + text=True, |
| 15 | + check=True, |
| 16 | + ).stdout |
| 17 | + |
| 18 | + git_output += subprocess.run( |
| 19 | + ["git", "submodule", "update", "--init", "--recursive"], |
| 20 | + capture_output=True, |
| 21 | + text=True, |
| 22 | + check=True, |
| 23 | + ).stdout |
| 24 | + |
| 25 | + os.chdir("..") |
| 26 | + |
| 27 | + build_output = subprocess.run( |
| 28 | + [ |
| 29 | + "/bin/bash", |
| 30 | + "-c", |
| 31 | + "source venv/bin/activate && " |
| 32 | + "poetry install --only docs && " |
| 33 | + "sphinx-build -M html underactuated /tmp/underactuated_doc && " |
| 34 | + "rm -rf book/python && " |
| 35 | + "cp -r /tmp/underactuated_doc/html book/python", |
| 36 | + ], |
| 37 | + capture_output=True, |
| 38 | + text=True, |
| 39 | + check=True, |
| 40 | + ).stdout |
| 41 | + |
| 42 | + # Now we can safely print headers and content |
| 43 | + print("Content-Type: text/html\n") |
| 44 | + print("<html><body>") |
| 45 | + print("<p>pulling repo...</p>") |
| 46 | + print(f"<pre>{git_output}</pre>") |
| 47 | + print("<p>done.</p>") |
| 48 | + print("<p>building documentation...</p>") |
| 49 | + print(f"<pre>{build_output}</pre>") |
| 50 | + print("<p>done.</p>") |
| 51 | + print("</body></html>") |
| 52 | + |
| 53 | +except Exception as e: |
| 54 | + print("Content-Type: text/html\n") |
| 55 | + print("<html><body>") |
| 56 | + print(f"<p>Error: {str(e)}</p>") |
| 57 | + print("</body></html>") |
0 commit comments