-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflask_server.py
More file actions
74 lines (62 loc) · 1.63 KB
/
flask_server.py
File metadata and controls
74 lines (62 loc) · 1.63 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
"""
Flask based server
"""
from flask import Flask, request
from utils.run_command import run_command
from utils.stream_template import _stream_template
app = Flask(
__name__,
static_folder='web/static',
template_folder='web/templates',
)
app.program_settings = {
'format_output': False,
}
app.runners = []
app.env_data = []
app.start_screen = []
app.history = []
@app.route('/', methods=['GET', 'POST'])
@app.route('/<main_font_size>', methods=['GET', 'POST'])
def index(main_font_size=1):
"""Root"""
runner = ''
source = ''
html = False
left_window_width = '50vw'
if request.method == 'POST':
runner = request.form['runner']
source = request.form['source']
left_window_width = request.form['left_window_width']
if not left_window_width:
left_window_width = '50vw'
if not runner:
rows = []
elif not source:
rows = []
elif runner == 'html':
rows = source.split('\n')
html = True
elif runner == '--history--':
rows = (y for y in app.history)
else:
rows = run_command(
runner,
source,
app.history,
format_output=app.program_settings['format_output']
)
if rows == []:
rows = app.start_screen
html = True
return app.response_class(_stream_template(
app,
'index.html',
left_window_width=left_window_width,
format_output=app.program_settings['format_output'],
main_font_size=main_font_size,
rows=rows,
html=html,
runners=app.runners,
env_data=app.env_data,
))