forked from hkarl/mw2pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpctrl.py
46 lines (40 loc) · 1.15 KB
/
httpctrl.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
"""
Simple webserver to trigger built process from outside.
"""
import subprocess
import re
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def welcome():
welcome = """
<h1>UPB mw2pdf converter manual trigger</h1>
<form action="build" method="get">
Docname:<br>
<input type="text" name="docname" = value="WP2_Deliverable_2.2">
<input type="submit" value="Build!">
</form>
"""
return welcome
@app.route("/build", methods=['GET'])
def build():
# get arguments
docname = request.args.get("docname", None)
# some minimal security
if not re.match(r'[\w+\.]+$', docname):
return "Malformed document name. Abort."
# kick-off build process
cmd = ["python",
"build.py",
"--ignore-fingerprint",
"--uml",
"--upload",
"--download",
"--latex",
"--document",
docname]
subprocess.Popen(cmd)
return "Started build process for <b>%s</b>. Updated document will be available (uploaded to the Wiki) in some minutes." % str(docname)
if __name__ == "__main__":
app.debug = False
app.run(host='0.0.0.0')