-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
89 lines (59 loc) · 2.42 KB
/
main.py
File metadata and controls
89 lines (59 loc) · 2.42 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import _thread
import yaml
from sanic import Sanic, response
from sanic.response import json
import os
from Task import Task
app = Sanic()
INSTALLED_COMPILERS_YML = 'installed_compilers.yml'
with open(INSTALLED_COMPILERS_YML, 'r') as yml_file:
installed_compilers = yaml.load(yml_file)
@app.route("/")
async def root(request):
return json({"wip": "wip"})
@app.route("/compile", methods=['POST'])
async def compile(request):
new_task = Task(request.form['task_id'][0],
request.form['output_files'][0])
new_task.save_input_files(request.files.get('0'))
_thread.start_new_thread(new_task.compile, (request.form['bash'][0],))
return json({"output": "success"})
@app.route("/install", methods=['POST'])
async def install(request):
compiler_name = request.form['compiler_name'][0]
if compiler_name in installed_compilers:
return json({"already added": "wip"})
installed_compilers.append(compiler_name)
yaml.dump(installed_compilers, open(INSTALLED_COMPILERS_YML, 'w'))
return json({"wip": "wip"})
@app.route("/uninstall", methods=['DELETE'])
async def uninstall(request):
compiler_name = request.form['compiler_name'][0]
if compiler_name not in installed_compilers:
return json({"already added": "wip"})
installed_compilers.remove(compiler_name)
yaml.dump(installed_compilers, open(INSTALLED_COMPILERS_YML, 'w'))
return json({"wip": "wip"})
@app.route("/installed_compilers", methods=['GET'])
async def get_installed_compilers(request):
return json({"installed_compilers": installed_compilers})
@app.route("/task", methods=['GET'])
async def get_state(request):
if 'id' not in request.args:
return json({"state": "id required"}, status=400)
task = Task.get_task(request.args['id'][0])
if task is None:
return json({"state": "not found"}, status=404)
return json({"id": task.id,
"state": task.get_state().name,
"output_log": task.output_log})
@app.route("/get_output_files", methods=['GET'])
async def get_output_files(request):
if 'id' not in request.args:
return json({"error": "id required"})
task = Task.get_task(request.args['id'][0])
if task is None:
return json({"error": "Task not found"}, status=404)
return await response.file(task.get_output_zip_path())
if __name__ == "__main__":
app.run(host="0.0.0.0", port=os.getenv('PORT', 7894))