diff --git a/fri/server/main.py b/fri/server/main.py index 51f8f97e..919e9ea2 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -1,10 +1,11 @@ from flask import Flask, request, jsonify, send_file, send_from_directory from werkzeug.utils import secure_filename import os +import subprocess from subprocess import call from pathlib import Path import json -import subprocess +import platform from flask_cors import CORS, cross_origin cur_path = os.path.dirname(os.path.abspath(__file__)) @@ -21,8 +22,10 @@ @app.route('/upload/', methods=['POST']) def upload(dir): apikey = request.args.get('apikey') - dirname = secure_filename(dir) + "_" + apikey - + if(apikey == None): + dirname = secure_filename(dir) + else: + dirname = secure_filename(dir) + "_" + apikey if 'files[]' not in request.files: resp = jsonify({'message': 'No file in the request'}) resp.status_code = 400 @@ -66,26 +69,38 @@ def upload(dir): def build(dir): graphml_file = request.args.get('fetch') apikey = request.args.get('apikey') - dirname = secure_filename(dir) + "_" + apikey + if(apikey == None): + dirname = secure_filename(dir) + else: + dirname = secure_filename(dir) + "_" + apikey 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) + if(platform.uname()[0]=='Windows'): + proc= call(["makestudy", makestudy_dir], shell=True, cwd=concore_path) + else: + proc = call(["./makestudy", makestudy_dir], 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) + resp.status_code = 500 + if(platform.uname()[0]=='Windows'): + call(["build"], cwd=dir_path, shell=True) + else: + call(["./build"], cwd=dir_path) return resp @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) + dir_name = secure_filename(dir) + dir_path = os.path.abspath(os.path.join(concore_path, dir_name)) + if(platform.uname()[0]=='Windows'): + proc=call(["debug"],shell=True, cwd=dir_path) + else: + proc = call(["./debug"], cwd=dir_path) if(proc == 0): resp = jsonify({'message': 'Close the pop window after obtaining result'}) resp.status_code = 201 @@ -98,9 +113,12 @@ def debug(dir): @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) + dir_name = secure_filename(dir) + dir_path = os.path.abspath(os.path.join(concore_path, dir_name)) + if(platform.uname()[0]=='Windows'): + proc=call(["run"],shell=True, cwd=dir_path) + else: + proc = call(["./run"], cwd=dir_path) if(proc == 0): resp = jsonify({'message': 'result prepared'}) resp.status_code = 201 @@ -112,9 +130,12 @@ def run(dir): @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) + dir_name = secure_filename(dir) + dir_path = os.path.abspath(os.path.join(concore_path, dir_name)) + if(platform.uname()[0]=='Windows'): + proc=call(["stop"],shell=True, cwd=dir_path) + else: + proc = call(["./stop"], cwd=dir_path) if(proc == 0): resp = jsonify({'message': 'resources cleaned'}) resp.status_code = 201 @@ -127,9 +148,12 @@ def stop(dir): @app.route('/clear/', methods=['POST']) def clear(dir): - dir = secure_filename(dir) - dir_path = os.path.abspath(os.path.join(concore_path, dir)) - proc = call(["./clear"], cwd=dir_path) + dir_name = secure_filename(dir) + dir_path = os.path.abspath(os.path.join(concore_path, dir_name)) + if(platform.uname()[0]=='Windows'): + proc=call(["clear"],shell=True, cwd=dir_path) + else: + proc = call(["./clear"], cwd=dir_path) if(proc == 0): resp = jsonify({'message': 'result deleted'}) resp.status_code = 201 @@ -161,7 +185,10 @@ def download(dir): @app.route('/destroy/', methods=['DELETE']) def destroy(dir): dir = secure_filename(dir) - proc = call(["./destroy", dir], cwd=concore_path) + if(platform.uname()[0]=='Windows'): + proc=call(["destroy"],shell=True, cwd=concore_path) + else: + proc = call(["./destroy"], cwd=concore_path) if(proc == 0): resp = jsonify({'message': 'Successfuly deleted Dirctory'}) resp.status_code = 201 diff --git a/fri/test.py b/fri/test.py index 684c6eff..d1c56f41 100644 --- a/fri/test.py +++ b/fri/test.py @@ -23,37 +23,37 @@ def build(dir, graphml, apikey): print(response.text) # function to debug -def debug(graphml): - url = "http://127.0.0.1:5000/debug/"+graphml +def debug(graphml, apikey): + url = "http://127.0.0.1:5000/debug/"+graphml+"?"+"apikey="+apikey response = requests.request("POST", url) print(response.text) # function to test run() method. -def run(graphml): - url = "http://127.0.0.1:5000/run/"+graphml +def run(graphml, apikey): + url = "http://127.0.0.1:5000/run/"+graphml+"?"+"apikey="+apikey response = requests.request("POST", url) print(response.text) -def clear(graphml): - url = "http://127.0.0.1:5000/clear/"+graphml +def clear(graphml, apikey): + url = "http://127.0.0.1:5000/clear/"+graphml+"?"+"apikey="+apikey response = requests.request("POST", url) print(response.text) -def stop(graphml): - url = "http://127.0.0.1:5000/stop/"+graphml +def stop(graphml, apikey): + url = "http://127.0.0.1:5000/stop/"+graphml+"?"+"apikey="+apikey response = requests.request("POST", url) print(response.text) #function to destroy dir. -def destroy(dir): - url = "http://127.0.0.1:5000/destroy/" + dir +def destroy(dir, apikey): + url = "http://127.0.0.1:5000/destroy/" + dir+"?"+"apikey="+apikey response = requests.request("DELETE", url) print(response.text) -def getFilesList(dir, sub_dir = ""): - url = "http://127.0.0.1:5000/getFilesList/" + dir + "?"+"fetch="+sub_dir +def getFilesList(apikey, dir, sub_dir = ""): + url = "http://127.0.0.1:5000/getFilesList/" + dir + "?"+"fetch="+sub_dir+"&"+"apikey="+apikey response = requests.request("POST", url) print(response.text) @@ -63,8 +63,8 @@ def openJupyter(): print(response.text) # function to test download() method. -def download(dir, subDir, fileName ): - url = "http://127.0.0.1:5000/download/"+dir+"?"+"fetchDir="+subDir+"&"+"fetch="+ fileName +def download(dir, subDir, fileName , apikey ): + url = "http://127.0.0.1:5000/download/"+dir+"?"+"fetchDir="+subDir+"&"+"fetch="+ fileName+"&"+"apikey="+apikey urllib.request.urlretrieve(url, fileName) # file list to be uploaded @@ -90,18 +90,18 @@ def download(dir, subDir, fileName ): time.sleep(6) method = input("methods - 1 for debug, 0 for run :") if method == "1": - debug("sample") + debug("sample", "xyz") else: - run("sample") + run("sample", "xyz") time.sleep(2) -stop("sample") +stop("sample", "xyz") time.sleep(2) -getFilesList("sample", "cu") -getFilesList("sample", "pym") +getFilesList("xyz", "sample", "CU") +getFilesList("xyz","sample", "PYM") time.sleep(5) -download("sample", "cu", "u") -clear("sample") -destroy("sample") +download("sample", "CU", "u", "xyz") +clear("sample", "xyz") +destroy("sample", "xyz") openJupyter() diff --git a/mkconcore.py b/mkconcore.py index 200771dc..96272ec3 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -921,4 +921,3 @@ os.chmod(outdir+"/maxtime",stat.S_IRWXU) os.chmod(outdir+"/params",stat.S_IRWXU) os.chmod(outdir+"/unlock",stat.S_IRWXU) -