-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_app.py
66 lines (58 loc) · 2.02 KB
/
run_app.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
from flask import Flask
from flask import render_template, render_template_string
from flask import request, session
import command_execute
from command_execute import CommandException
from progress import Progress
app = Flask(__name__)
app.secret_key = 'A0Zr98j/3yX R~XHZ!jmN]LWX/,?RT'
@app.route('/')
def try_sed():
render_dict = {}
if "progress" not in session:
session["progress"] = Progress()
render_dict["dialog"] = session["progress"].get_dialog()
return render_template('index.html', **render_dict)
@app.route('/submit', methods=['POST'])
def submit():
data = request.data
response = {"success": False}
command = request.form.get("input")
entry_check = {"success": False}
result_check = {"success": False}
if "progress" not in session:
session["progress"] = Progress()
if command:
progress = session["progress"]
entry_check = progress.check_entry(command)
if entry_check["continue"]:
try:
result = command_execute.execute(command)
except CommandException, error:
response["error"] = "Error: %s" %error
else:
response = {"success": True, "result": result}
result_check = progress.check_result(result)
else:
response = {"success": True, "result": ""}
else:
response["error"] = "Must enter a command."
if entry_check["success"] or result_check["success"]:
progress.next_step()
session.modified = True
dialog = progress.get_dialog()
response["dialog"] = dialog
response = json.dumps(response)
return render_template_string(response)
@app.route('/reset_step', methods=['POST'])
def reset_step():
reset = Progress()
session["progress"] = reset
return str(reset.get_step()[0]["text"])
@app.route('/get_step', methods=['POST'])
def get_step():
step = session["progress"].get_step()
return str(step)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9980, debug=True)