From 9e928ccdc13a0073ac8f52cd2ead555402cfae30 Mon Sep 17 00:00:00 2001 From: parteekcoder Date: Sat, 18 Feb 2023 15:50:13 +0530 Subject: [PATCH 1/2] issue #31 issue #31 solved , We have to enable shell=True Also There is One more bug that is if os.path.exists(dir_path) it will not enter if block and resp will not be defined and it also produces --- fri/server/main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fri/server/main.py b/fri/server/main.py index e546761..8426249 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -5,6 +5,7 @@ from pathlib import Path import json import subprocess +from flask_cors import CORS, cross_origin cur_path = os.path.dirname(os.path.abspath(__file__)) concore_path = os.path.abspath(os.path.join(cur_path, '../../')) @@ -13,6 +14,9 @@ app = Flask(__name__) app.secret_key = "secret key" +cors = CORS(app) +app.config['CORS_HEADERS'] = 'Content-Type' + # To upload multiple file. For example, /upload/test?apikey=xyz @app.route('/upload/', methods=['POST']) def upload(dir): @@ -66,14 +70,17 @@ def build(dir): makestudy_dir = dirname + "/" + graphml_file #for makestudy dir_path = os.path.abspath(os.path.join(concore_path, graphml_file)) #path for ./build if not os.path.exists(dir_path): - proc = call(["./makestudy", makestudy_dir], cwd=concore_path) + proc = call(["makestudy", makestudy_dir],shell=True, cwd=concore_path) if(proc == 0): resp = jsonify({'message': 'Directory successfully created'}) resp.status_code = 201 else: resp = jsonify({'message': 'There is an Error'}) resp.status_code = 500 - call(["./build"], cwd=dir_path) + else: + resp= jsonify({"message":"Success"}) + resp.status_code=200 + call(["build"],shell=True, cwd=dir_path) return resp From 5e0f3d82ca2d44f29bd620a71ffc8cf0e29197a5 Mon Sep 17 00:00:00 2001 From: parteekcoder Date: Sun, 19 Feb 2023 01:25:20 +0530 Subject: [PATCH 2/2] Update main.py --- fri/server/main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fri/server/main.py b/fri/server/main.py index 8426249..79bff9a 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -84,11 +84,12 @@ def build(dir): return resp +# Give the directory of the build files that are build using ./build @app.route('/debug/', methods=['POST']) def debug(dir): dir = secure_filename(dir) dir_path = os.path.abspath(os.path.join(concore_path, dir)) - proc = call(["./debug"], cwd=dir_path) + proc = call(["debug"],shell=True , cwd=dir_path) if(proc == 0): resp = jsonify({'message': 'Close the pop window after obtaining result'}) resp.status_code = 201 @@ -99,11 +100,13 @@ def debug(dir): return resp +# Give the directory of the build files that are build using ./build @app.route('/run/', methods=['POST']) def run(dir): dir = secure_filename(dir) dir_path = os.path.abspath(os.path.join(concore_path, dir)) - proc = call(["./run"], cwd=dir_path) + print(dir_path) + proc = call(["run"],shell=True, cwd=dir_path) if(proc == 0): resp = jsonify({'message': 'result prepared'}) resp.status_code = 201 @@ -113,11 +116,12 @@ def run(dir): resp.status_code = 500 return resp +# Give the directory of the build files that are build using ./build @app.route('/stop/', methods=['POST']) def stop(dir): dir = secure_filename(dir) dir_path = os.path.abspath(os.path.join(concore_path, dir)) - proc = call(["./stop"], cwd=dir_path) + proc = call(["stop"],shell=True, cwd=dir_path) if(proc == 0): resp = jsonify({'message': 'resources cleaned'}) resp.status_code = 201 @@ -132,7 +136,7 @@ def stop(dir): def clear(dir): dir = secure_filename(dir) dir_path = os.path.abspath(os.path.join(concore_path, dir)) - proc = call(["./clear"], cwd=dir_path) + proc = call(["clear"],shell=True, cwd=dir_path) if(proc == 0): resp = jsonify({'message': 'result deleted'}) resp.status_code = 201 @@ -164,7 +168,7 @@ def download(dir): @app.route('/destroy/', methods=['DELETE']) def destroy(dir): dir = secure_filename(dir) - proc = call(["./destroy", dir], cwd=concore_path) + proc = call(["destroy", dir],shell=True, cwd=concore_path) if(proc == 0): resp = jsonify({'message': 'Successfuly deleted Dirctory'}) resp.status_code = 201 @@ -185,7 +189,7 @@ def getFilesList(dir): return res -@app.route('/openJupyter/', methods=['POST']) +@app.route('/openJupyter', methods=['POST']) def openJupyter(): proc = subprocess.Popen(['jupyter', 'lab'], shell=False, stdout=subprocess.PIPE, cwd=concore_path) if proc.poll() is None: