Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion fri/server/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from asyncio import subprocess
from flask import Flask, request, jsonify, send_file, send_from_directory
from werkzeug.utils import secure_filename
import os
from subprocess import call
from subprocess import call, run, Popen
from pathlib import Path


Expand Down Expand Up @@ -47,6 +48,59 @@ def upload(dir):
resp.status_code = 500
return resp

@app.route('/build/<dir>', methods=['POST'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dir should be the whole input as in "demo/sample" rather than hard-coding "demo" below.

def build(dir):
makestudy_dir = "demo" + "/" + dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makestduy_dir = dir
(therefore, avoid makestudy_dir)

cur_path = os.getcwd()
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
dir_path = os.path.abspath(os.path.join(concore_path, dir))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dir" here must be replaced by a splitted version to get the "sample" below:
split by "/"
as in dir = demo/sample <--- we want the "sample" here.

if not os.path.exists(secure_filename(dir_path)):
p1 = call(["./makestudy", makestudy_dir], cwd=concore_path)
if(p1 == 0):
resp = jsonify({'message': 'Directory successfully created'})
resp.status_code = 201
return resp
else:
resp = jsonify({'message': 'There is an Error'})
resp.status_code = 500
return resp
call(["./build"], cwd=dir_path)
return resp


@app.route('/debug/<dir>', methods=['POST'])
def debug(dir):
cur_path = os.getcwd()
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
dir_path = os.path.abspath(os.path.join(concore_path, dir))
p1 = call(["./debug"], cwd=dir_path)
if(p1 == 0):
resp = jsonify({'message': 'Close the pop window after obtaing result'})
resp.status_code = 201
return resp
else:
resp = jsonify({'message': 'There is an Error'})
resp.status_code = 500
return resp



@app.route('/destroy/<dir>', methods=['POST'])
def destroy(dir):
cur_path = os.getcwd()
concore_path = os.path.abspath(os.path.join(cur_path, '../../'))
p1 = call(["./destroy", dir], cwd=concore_path)
if(p1 == 0):
resp = jsonify({'message': 'Successfuly deleted Dirctory'})
resp.status_code = 201
return resp
else:
resp = jsonify({'message': 'There is an Error'})
resp.status_code = 500
return resp



# To execute any python file. For example, /execute/test?apikey=xyz
@app.route('/execute/<dir>', methods=['POST'])
def execute(dir):
Expand Down
Loading