66import json
77import subprocess
88
9+ cur_path = os .path .dirname (os .path .abspath (__file__ ))
10+ concore_path = os .path .abspath (os .path .join (cur_path , '../../' ))
11+
912
1013app = Flask (__name__ )
1114app .secret_key = "secret key"
@@ -26,8 +29,6 @@ def upload(dir):
2629 errors = {}
2730 success = False
2831
29- cur_path = os .path .dirname (os .path .abspath (__file__ ))
30- concore_path = os .path .abspath (os .path .join (cur_path , '../../' ))
3132 directory_name = os .path .abspath (os .path .join (concore_path , secure_filename (dirname )))
3233
3334 if not os .path .isdir (directory_name ):
@@ -54,58 +55,15 @@ def upload(dir):
5455 resp .status_code = 500
5556 return resp
5657
57- # To execute any python file. For example, /execute/test?apikey=xyz
58- @app .route ('/execute/<dir>' , methods = ['POST' ])
59- def execute (dir ):
60- apikey = request .args .get ('apikey' )
61- dirname = dir + "_" + apikey
62-
63- if 'file' not in request .files :
64- resp = jsonify ({'message' : 'No file in the request' })
65- resp .status_code = 400
66- return resp
67-
68- file = request .files ['file' ]
69-
70- if file .filename == '' :
71- resp = jsonify ({'message' : 'No file selected for Executing' })
72- resp .status_code = 400
73- return resp
74-
75- errors = {}
76- success = False
77-
78- if not os .path .exists (secure_filename (dirname )):
79- os .makedirs (secure_filename (dirname ))
80-
81- if file :
82- filename = secure_filename (file .filename )
83- file .save (secure_filename (dirname )+ "/" + filename )
84- output_filename = filename + ".out"
85- file_path = secure_filename (dirname ) + "/" + filename
86- outputfile_path = secure_filename (dirname )+ "/" + output_filename
87- f = open (outputfile_path , "w" )
88- call (["nohup" , "python3" , file_path ], stdout = f )
89- success = True
9058
91- if success :
92- resp = jsonify ({'message' : 'Files successfully executed' })
93- resp .status_code = 201
94- return resp
95- else :
96- resp = jsonify (errors )
97- resp .status_code = 500
98- return resp
9959
100- # to download /build/<dir>?fetch=<graphml>. For example, /build/test?fetch=sample1
60+ # to download /build/<dir>?fetch=<graphml>. For example, /build/test?fetch=sample1&apikey=xyz
10161@app .route ('/build/<dir>' , methods = ['POST' ])
10262def build (dir ):
10363 graphml_file = request .args .get ('fetch' )
10464 apikey = request .args .get ('apikey' )
10565 dirname = dir + "_" + apikey
10666 makestudy_dir = dirname + "/" + graphml_file #for makestudy
107- cur_path = os .path .dirname (os .path .abspath (__file__ ))
108- concore_path = os .path .abspath (os .path .join (cur_path , '../../' ))
10967 dir_path = os .path .abspath (os .path .join (concore_path , graphml_file )) #path for ./build
11068 if not os .path .exists (secure_filename (dir_path )):
11169 proc = call (["./makestudy" , makestudy_dir ], cwd = concore_path )
@@ -121,8 +79,6 @@ def build(dir):
12179
12280@app .route ('/debug/<dir>' , methods = ['POST' ])
12381def debug (dir ):
124- cur_path = os .path .dirname (os .path .abspath (__file__ ))
125- concore_path = os .path .abspath (os .path .join (cur_path , '../../' ))
12682 dir_path = os .path .abspath (os .path .join (concore_path , dir ))
12783 proc = call (["./debug" ], cwd = dir_path )
12884 if (proc == 0 ):
@@ -134,15 +90,53 @@ def debug(dir):
13490 resp .status_code = 500
13591 return resp
13692
93+
94+ @app .route ('/run/<dir>' , methods = ['POST' ])
95+ def run (dir ):
96+ dir_path = os .path .abspath (os .path .join (concore_path , dir ))
97+ proc = call (["./run" ], cwd = dir_path )
98+ if (proc == 0 ):
99+ resp = jsonify ({'message' : 'result prepared' })
100+ resp .status_code = 201
101+ return resp
102+ else :
103+ resp = jsonify ({'message' : 'There is an Error' })
104+ resp .status_code = 500
105+ return resp
106+
107+ @app .route ('/stop/<dir>' , methods = ['POST' ])
108+ def stop (dir ):
109+ dir_path = os .path .abspath (os .path .join (concore_path , dir ))
110+ proc = call (["./stop" ], cwd = dir_path )
111+ if (proc == 0 ):
112+ resp = jsonify ({'message' : 'resources cleaned' })
113+ resp .status_code = 201
114+ return resp
115+ else :
116+ resp = jsonify ({'message' : 'There is an Error' })
117+ resp .status_code = 500
118+ return resp
119+
120+
121+ @app .route ('/clear/<dir>' , methods = ['POST' ])
122+ def clear (dir ):
123+ dir_path = os .path .abspath (os .path .join (concore_path , dir ))
124+ proc = call (["./clear" ], cwd = dir_path )
125+ if (proc == 0 ):
126+ resp = jsonify ({'message' : 'result deleted' })
127+ resp .status_code = 201
128+ return resp
129+ else :
130+ resp = jsonify ({'message' : 'There is an Error' })
131+ resp .status_code = 500
132+ return resp
133+
137134# to download /download/<dir>?fetch=<downloadfile>. For example, /download/test?fetch=example.py.out&apikey=xyz
138135@app .route ('/download/<dir>' , methods = ['POST' , 'GET' ])
139136def download (dir ):
140137 download_file = request .args .get ('fetch' )
141138 apikey = request .args .get ('apikey' )
142139 dirname = dir + "_" + apikey
143-
144- cur_path = os .path .dirname (os .path .abspath (__file__ ))
145- concore_path = os .path .abspath (os .path .join (cur_path , '../../' ))
146140 directory_name = os .path .abspath (os .path .join (concore_path , secure_filename (dirname )))
147141
148142
@@ -161,9 +155,6 @@ def download(dir):
161155
162156@app .route ('/destroy/<dir>' , methods = ['DELETE' ])
163157def destroy (dir ):
164- # cur_path = os.getcwd()
165- cur_path = os .path .dirname (os .path .abspath (__file__ ))
166- concore_path = os .path .abspath (os .path .join (cur_path , '../../' ))
167158 proc = call (["./destroy" , dir ], cwd = concore_path )
168159 if (proc == 0 ):
169160 resp = jsonify ({'message' : 'Successfuly deleted Dirctory' })
@@ -176,9 +167,6 @@ def destroy(dir):
176167
177168@app .route ('/getFilesList/<dir>' , methods = ['POST' ])
178169def getFilesList (dir ):
179- # cur_path = os.getcwd()
180- cur_path = os .path .dirname (os .path .abspath (__file__ ))
181- concore_path = os .path .abspath (os .path .join (cur_path , '../../' ))
182170 dir_path = os .path .abspath (os .path .join (concore_path , dir ))
183171 res = []
184172 res = os .listdir (dir_path )
@@ -188,10 +176,6 @@ def getFilesList(dir):
188176
189177@app .route ('/openJupyter/' , methods = ['POST' ])
190178def openJupyter ():
191- # cur_path = os.getcwd()
192- cur_path = os .path .dirname (os .path .abspath (__file__ ))
193- print (cur_path )
194- concore_path = os .path .abspath (os .path .join (cur_path , '../../' ))
195179 proc = subprocess .Popen (['jupyter' , 'lab' ], shell = False , stdout = subprocess .PIPE , cwd = concore_path )
196180 if proc .poll () is None :
197181 resp = jsonify ({'message' : 'Successfuly opened Jupyter' })
0 commit comments