Skip to content

Commit e10b90c

Browse files
Merge branch 'ControlCore-Project:dev' into dev
2 parents aa42f51 + e199b32 commit e10b90c

5 files changed

Lines changed: 139 additions & 121 deletions

File tree

fri/server/main.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ def build(dir):
149149
if(out_dir == None or out_dir == ""):
150150
if(docker == 'true'):
151151
try:
152-
output_bytes = subprocess.check_output(["./makedocker", makestudy_dir], cwd=concore_path)
152+
output_bytes = subprocess.check_output([r"./makedocker", makestudy_dir], cwd=concore_path)
153153
output_str = output_bytes.decode("utf-8")
154154
proc = 0
155155
except subprocess.CalledProcessError as e:
156156
output_str = f"Docker study creation failed with return code {e.returncode} (check duplicate directory)"
157157
proc = 1
158158
else:
159159
try:
160-
output_bytes = subprocess.check_output(["./makestudy", makestudy_dir], cwd=concore_path)
160+
output_bytes = subprocess.check_output([r"./makestudy", makestudy_dir], cwd=concore_path)
161161
output_str = output_bytes.decode("utf-8")
162162
proc = 0
163163
except subprocess.CalledProcessError as e:
@@ -166,15 +166,15 @@ def build(dir):
166166
else:
167167
if(docker == 'true'):
168168
try:
169-
output_bytes = subprocess.check_output(["./makedocker", makestudy_dir, out_dir], cwd=concore_path)
169+
output_bytes = subprocess.check_output([r"./makedocker", makestudy_dir, out_dir], cwd=concore_path)
170170
output_str = output_bytes.decode("utf-8")
171171
proc = 0
172172
except subprocess.CalledProcessError as e:
173173
output_str = f"Docker study creation failed with return code {e.returncode} (check duplicate directory)"
174174
proc = 1
175175
else:
176176
try:
177-
output_bytes = subprocess.check_output(["./makestudy", makestudy_dir, out_dir], cwd=concore_path)
177+
output_bytes = subprocess.check_output([r"./makestudy", makestudy_dir, out_dir], cwd=concore_path)
178178
output_str = output_bytes.decode("utf-8")
179179
proc = 0
180180
except subprocess.CalledProcessError as e:
@@ -201,17 +201,17 @@ def build(dir):
201201
proc=call(["params", params],shell=True, cwd=dir_path)
202202
else:
203203
try:
204-
output_bytes = subprocess.check_output("./build", cwd=dir_path)
204+
output_bytes = subprocess.check_output(r"./build", cwd=dir_path)
205205
output_str = output_str + output_bytes.decode("utf-8")
206206
resp = jsonify({'message': 'Directory successfully created', 'output': output_str})
207207
except subprocess.CalledProcessError as e:
208208
output_str = f"Build failed with return code {e.returncode}"
209209
resp = jsonify({'message': 'Build Failed', 'output': output_str})
210210
resp.status_code = 500
211211
if(maxtime != None and maxtime != ''):
212-
proc=call(["./maxtime", maxtime], cwd=dir_path)
212+
proc=call([r"./maxtime", maxtime], cwd=dir_path)
213213
if(params != None and params != ''):
214-
proc=call(["./params", params], cwd=dir_path)
214+
proc=call([r"./params", params], cwd=dir_path)
215215
return resp
216216

217217
@app.route('/debug/<dir>', methods=['POST'])
@@ -221,7 +221,7 @@ def debug(dir):
221221
if(platform.uname()[0]=='Windows'):
222222
proc = call(["debug"],shell=True, cwd=dir_path)
223223
else:
224-
proc = call(["./debug"], cwd=dir_path)
224+
proc = call([r"./debug"], cwd=dir_path)
225225
if(proc == 0):
226226
resp = jsonify({'message': 'Close the pop window after obtaining result'})
227227
resp.status_code = 201
@@ -238,7 +238,7 @@ def run(dir):
238238
if(platform.uname()[0]=='Windows'):
239239
proc = call(["run"],shell=True, cwd=dir_path)
240240
else:
241-
proc = call(["./run"], cwd=dir_path)
241+
proc = call([r"./run"], cwd=dir_path)
242242
if(proc == 0):
243243
resp = jsonify({'message': 'result prepared'})
244244
resp.status_code = 201
@@ -255,7 +255,7 @@ def stop(dir):
255255
if(platform.uname()[0]=='Windows'):
256256
proc = call(["stop"],shell=True, cwd=dir_path)
257257
else:
258-
proc = call(["./stop"], cwd=dir_path)
258+
proc = call([r"./stop"], cwd=dir_path)
259259
if(proc == 0):
260260
resp = jsonify({'message': 'resources cleaned'})
261261
resp.status_code = 201
@@ -280,11 +280,11 @@ def clear(dir):
280280
if(params != None and params != ''):
281281
proc = call(["params", params],shell=True, cwd=dir_path)
282282
else:
283-
proc = call(["./clear"], cwd=dir_path)
283+
proc = call([r"./clear"], cwd=dir_path)
284284
if(maxtime != None and maxtime != ''):
285-
proc = call(["./maxtime", maxtime], cwd=dir_path)
285+
proc = call([r"./maxtime", maxtime], cwd=dir_path)
286286
if(params != None and params != ''):
287-
proc = call(["./params", params], cwd=dir_path)
287+
proc = call([r"./params", params], cwd=dir_path)
288288
if(proc == 0):
289289
resp = jsonify({'message': 'result deleted'})
290290
resp.status_code = 201
@@ -308,9 +308,9 @@ def contribute():
308308
proc=check_output(["contribute",STUDY_NAME,STUDY_NAME_PATH,AUTHOR_NAME,BRANCH_NAME,PR_TITLE,PR_BODY],cwd=concore_path,shell=True)
309309
else:
310310
if len(BRANCH_NAME)==0:
311-
proc = check_output(["./contribute",STUDY_NAME,STUDY_NAME_PATH,AUTHOR_NAME],cwd=concore_path)
311+
proc = check_output([r"./contribute",STUDY_NAME,STUDY_NAME_PATH,AUTHOR_NAME],cwd=concore_path)
312312
else:
313-
proc = check_output(["./contribute",STUDY_NAME,STUDY_NAME_PATH,AUTHOR_NAME,BRANCH_NAME,PR_TITLE,PR_BODY],cwd=concore_path)
313+
proc = check_output([r"./contribute",STUDY_NAME,STUDY_NAME_PATH,AUTHOR_NAME,BRANCH_NAME,PR_TITLE,PR_BODY],cwd=concore_path)
314314
output_string = proc.decode()
315315
status=200
316316
if output_string.find("/pulls/")!=-1:
@@ -349,7 +349,7 @@ def destroy(dir):
349349
if(platform.uname()[0]=='Windows'):
350350
proc = call(["destroy", dir],shell=True, cwd=concore_path)
351351
else:
352-
proc = call(["./destroy", dir], cwd=concore_path)
352+
proc = call([r"./destroy", dir], cwd=concore_path)
353353
if(proc == 0):
354354
resp = jsonify({'message': 'Successfuly deleted Dirctory'})
355355
resp.status_code = 201
@@ -367,11 +367,11 @@ def library(dir):
367367
library_path = request.args.get('path')
368368
proc = 0
369369
if (library_path == None or library_path == ''):
370-
library_path = "../tools"
370+
library_path = r"../tools"
371371
if(platform.uname()[0]=='Windows'):
372-
proc = subprocess.check_output(["..\library", library_path, filename],shell=True, cwd=dir_path)
372+
proc = subprocess.check_output([r"..\library", library_path, filename],shell=True, cwd=dir_path)
373373
else:
374-
proc = subprocess.check_output(["../library", library_path, filename], cwd=dir_path)
374+
proc = subprocess.check_output([r"../library", library_path, filename], cwd=dir_path)
375375
if(proc != 0):
376376
resp = jsonify({'message': proc.decode("utf-8")})
377377
resp.status_code = 201

fri/test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from cgi import test
21
import requests
32
import os
43
import urllib.request
54
import time
65

76
# function to test upload() method.
8-
97
def upload(files):
108
url = "http://127.0.0.1:5000/upload/test?apikey=xyz"
119
payload={}
@@ -62,8 +60,13 @@ def openJupyter():
6260

6361
# function to test download() method.
6462
def download(dir, subDir, fileName , apikey ):
65-
url = "http://127.0.0.1:5000/download/"+dir+"?"+"fetchDir="+subDir+"&"+"fetch="+ fileName+"&"+"apikey="+apikey
66-
urllib.request.urlretrieve(url, fileName)
63+
url = "http://127.0.0.1:5000/download/" + dir + "?" + "fetchDir=" + subDir + "&" + "fetch=" + fileName + "&" + "apikey=" + apikey
64+
response = requests.get(url)
65+
if response.status_code == 200:
66+
with open(fileName, 'wb') as f:
67+
f.write(response.content)
68+
else:
69+
print(f"Failed to download: {response.status_code}, {response.text}")
6770

6871
# file list to be uploaded
6972
cur_path = os.path.dirname(os.path.abspath(__file__))

makestudy

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
#!/bin/bash
2-
if [ $# == 0 ]
3-
then
4-
echo "Make a concore study "
1+
#!/usr/bin/env bash
2+
3+
if [ "$#" -eq 0 ]; then
4+
echo "Make a concore study"
55
echo " ./makestudy path/name.graphml"
66
echo " ./makestudy path/name.graphml study"
77
echo "In the first case, the name of the study is the same as the name of the .graphml"
88
echo "In either case, source files come from the same path as the .graphml"
99
echo "The equivalent mkconcore.py is displayed"
1010
exit
1111
fi
12-
graphml=$1
13-
if [ -e $graphml ]
14-
then
15-
sourcedir=$(dirname "$graphml")
12+
13+
graphml="$1"
14+
15+
if [ -e "$graphml" ]; then
16+
sourcedir="$(dirname "$graphml")"
1617
else
17-
graphml=$graphml'.graphml'
18-
if [ -e $graphml ]
19-
then
20-
sourcedir=$(dirname "$graphml")
18+
graphml="${graphml}.graphml"
19+
if [ -e "$graphml" ]; then
20+
sourcedir="$(dirname "$graphml")"
2121
else
2222
echo "$graphml does not exist"
2323
exit
2424
fi
2525
fi
26-
if [ $# = 1 ]
27-
then
28-
studydir=`basename ${graphml%\.*}`
26+
27+
if [ "$#" -eq 1 ]; then
28+
studydir="$(basename "${graphml%.*}")"
2929
else
30-
studydir=$2
30+
studydir="$2"
3131
fi
32-
if [ -e $studydir ]
33-
then
34-
echo "cannot make $studydir because one already exists with that name"
35-
echo "either do ./destroy $studydir, or choose a unique name as 2nd arg"
32+
33+
if [ -e "$studydir" ]; then
34+
echo "Cannot make $studydir because one already exists with that name"
35+
echo "Either do ./destroy $studydir, or choose a unique name as 2nd arg"
36+
exit
3637
else
37-
which osascript >/dev/null
38-
if [ $? == 0 ]
39-
then
40-
echo "python3 mkconcore.py $graphml $sourcedir $studydir macos"
41-
python3 mkconcore.py $graphml $sourcedir $studydir macos
38+
if command -v osascript >/dev/null; then
39+
echo "python3 mkconcore.py \"$graphml\" \"$sourcedir\" \"$studydir\" macos"
40+
python3 mkconcore.py "$graphml" "$sourcedir" "$studydir" macos
4241
else
43-
echo "python3 mkconcore.py $graphml $sourcedir $studydir ubuntu"
44-
python3 mkconcore.py $graphml $sourcedir $studydir ubuntu
42+
echo "python3 mkconcore.py \"$graphml\" \"$sourcedir\" \"$studydir\" ubuntu"
43+
python3 mkconcore.py "$graphml" "$sourcedir" "$studydir" ubuntu
4544
fi
46-
fi
45+
fi

makestudy.bat

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
@echo off
2-
if dummy%~n2 == dummy (
3-
if dummy%~x1 == dummy.graphml (
4-
echo python mkconcore.py %~d1%~p1%~n1%~x1 %~d1%~p1 %~n1 windows
5-
python mkconcore.py %~d1%~p1%~n1%~x1 %~d1%~p1 %~n1 windows
6-
) else (
7-
echo python mkconcore.py %~d1%~p1%~n1.graphml %~d1%~p1 %~n1 windows
8-
python mkconcore.py %~d1%~p1%~n1.graphml %~d1%~p1 %~n1 windows
9-
)
2+
setlocal EnableDelayedExpansion
3+
4+
:: Extracting parameters safely
5+
set "file1=%~f1"
6+
set "file2=%~2"
7+
set "dir1=%~dp1"
8+
set "name1=%~n1"
9+
set "ext1=%~x1"
10+
11+
:: Handling spaces in paths by ensuring the format remains intact
12+
set "file1=!file1:\=\\!"
13+
set "dir1=!dir1:\=\\!"
14+
15+
:: If the second argument (file2) is not provided
16+
if not defined file2 (
17+
if /I "%ext1%"==".graphml" (
18+
echo python mkconcore.py "!file1!" "!dir1!" "!name1!" windows
19+
python mkconcore.py "!file1!" "!dir1!" "!name1!" windows
20+
) else (
21+
echo python mkconcore.py "!dir1!!name1!.graphml" "!dir1!" "!name1!" windows
22+
python mkconcore.py "!dir1!!name1!.graphml" "!dir1!" "!name1!" windows
23+
)
1024
) else (
11-
if dummy%~x1 == dummy.graphml (
12-
echo python mkconcore.py %~d1%~p1%~n1%~x1 %~d1%~p1 %~n2 windows
13-
python mkconcore.py %~d1%~p1%~n1%~x1 %~d1%~p1 %~n2 windows
14-
) else (
15-
echo python mkconcore.py %~d1%~p1%~n1.graphml %~d1%~p1 %~n2 windows
16-
python mkconcore.py %~d1%~p1%~n1.graphml %~d1%~p1 %~n2 windows
17-
)
18-
)
25+
if /I "%ext1%"==".graphml" (
26+
echo python mkconcore.py "!file1!" "!dir1!" "!file2!" windows
27+
python mkconcore.py "!file1!" "!dir1!" "!file2!" windows
28+
) else (
29+
echo python mkconcore.py "!dir1!!name1!.graphml" "!dir1!" "!file2!" windows
30+
python mkconcore.py "!dir1!!name1!.graphml" "!dir1!" "!file2!" windows
31+
)
32+
)
33+
34+
endlocal

0 commit comments

Comments
 (0)