-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeOnTheFly.py
More file actions
executable file
·73 lines (59 loc) · 2.44 KB
/
CodeOnTheFly.py
File metadata and controls
executable file
·73 lines (59 loc) · 2.44 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
#! /usr/bin/python3
import os
import sys
import argparse
import utils.ttyd as ttyd
import utils.utils as utils # Don't you love to see this?
import utils.config as config
from flask import Flask, flash, request, redirect, url_for
from waitress import serve
from werkzeug.utils import secure_filename
from werkzeug.wrappers import response
utils.validate_config()
CodeOnTheFly = Flask(__name__)
# Beautiful isn't it?
parser = argparse.ArgumentParser(description='CodeOnTheFly Help Menu')
parser.add_argument('-v', "--version", action='store_true',
help='Show the current app version and exit.')
parser.add_argument("--no-check", action='store_true',
help='Ignore checking for dependencies.')
# Parse them all!
args = parser.parse_args()
if args.version: print(config.app_info['version']), exit(0)
print(f"""
______ __ ____ ________ ________
/ ____/___ ____/ /__ / __ \____/_ __/ /_ ___ / ____/ /_ __
/ / / __ \/ __ / _ \/ / / / __ \/ / / __ \/ _ \/ /_ / / / / /
/ /___/ /_/ / /_/ / __/ /_/ / / / / / / / / / __/ __/ / / /_/ /
\____/\____/\__,_/\___/\____/_/ /_/_/ /_/ /_/\___/_/ /_/\__, /
/____/
By {config.app_info["author"]} - Version: {config.app_info["version"]}
""")
if not args.no_check: utils.check_dependencies()
@CodeOnTheFly.errorhandler(404)
def invalid_route(e):
return f"""
The requested page was not found!<br>CodeOnTheFly {config.app_info["version"]}
""", 404
@CodeOnTheFly.route('/', methods=['GET', 'POST'])
def handle_api():
if request.method == 'POST' or request.method == 'GET':
if 'code' not in request.files:
return "No file uploaded!", 400
file = request.files['code']
if file and utils.is_allowed(file.filename):
filename = secure_filename(file.filename)
return ttyd.generate_session(
utils.create_workspace(file, filename), filename,
utils.which_compiler(filename))
if __name__ == '__main__':
if config.flask_configuration['production']:
print("[ℹ️] Running in production mode.")
serve(CodeOnTheFly,
host=config.flask_configuration['host'],
port=config.flask_configuration['port'],)
else:
print("[ℹ️] Running in non-production mode.")
CodeOnTheFly.run(host=config.flask_configuration['host'],
port=config.flask_configuration['port'],
debug=config.flask_configuration['debug'])