-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
43 lines (29 loc) · 959 Bytes
/
main.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
from flask import Flask, jsonify, request, render_template, make_response
import time
from subprocess import Popen, PIPE
import os
app = Flask(__name__, static_folder="web", template_folder="web")
def serve_homepage():
return render_template("main.html")
def process_post():
code = request.form['code']
file_name = "temp/" + str(time.time()) + ".txt"
file1 = open(file_name, "w")
file1.write(code)
file1.close()
process = Popen(["build/QSim", file_name], stdout=PIPE)
(output, err) = process.communicate()
exit_code = process.wait()
return output
@app.route('/', methods=['POST', 'GET'])
def index():
if request.method == 'POST':
return process_post()
else:
return serve_homepage()
@app.route('/sw.js')
def sw_js():
headers = {'Content-Type': 'application/javascript'}
return make_response(render_template('sw.js'),200,headers)
if __name__ == '__main__':
app.run()