-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
72 lines (59 loc) · 2.19 KB
/
app.py
File metadata and controls
72 lines (59 loc) · 2.19 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
# imports
from flask import Flask, request, jsonify, send_file, render_template
import traceback
import os
# importing database created from the database.py file
from database import db
from getBlock import getblock
from addBlock import addblock
from codeGen import codeGenerator
# API definition
app = Flask(__name__)
# Webpage to be made for this route
@app.route("/")
def home():
return render_template('index.html')
# webpage for adding a block to the database
@app.route("/addBlock")
def addBlockPage():
return render_template("addBlock.html")
# endpoint for creating a block entry in the database
@app.route("/addblockrequest", methods=["POST"])
def addBlock():
blockName = str(request.form['blockName'])
args = str(request.form['args'])
filePath = str(request.form['filePath'])
out = str(request.form['out'])
ins = str(request.form['in'])
requestComp = addblock(blockName, args, ins, out, filePath)
return render_template("successfullBlock.html", blockName=requestComp)
# endpoint to show all the users
@app.route("/getBlocks", methods=["GET"])
def get_blocks():
qtype = request.args.get('type')
if(qtype == None):
return jsonify({"message": "inavlied query string"})
allBlocks = getblock(qtype)
return jsonify({"Blocks": [allBlocks.val()]})
# this code generates a cov_file in which the resulting code resides till now
@app.route('/generateCode', methods=['POST', 'GET'])
def block():
try:
# json file with the requirements from the client side
json_ = request.json
# getting file paths from the database
# getting the json files and list of filepaths from the json file
# json_[filePaths] is the list containing the relative file paths of the files
fileStatus = codeGenerator(json_)
return jsonify({'fileStatus': fileStatus})
except:
return jsonify({'trace': traceback.format_exc()})
@app.route("/convertedFile")
def DownloadLogFile():
try:
filepathMaster = os.path.join(os.getcwd(), "covFile.py")
return send_file(filepathMaster, as_attachment=True)
except:
return jsonify({'trace': traceback.format_exc()})
if __name__ == '__main__':
app.run(debug=True)