-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyserve.py
executable file
·95 lines (74 loc) · 2.33 KB
/
pyserve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
import os
from flask import Flask, send_from_directory, request
class dirmanager:
def __init__(self,programdir):
self.programdir = programdir
self.subjectParentDir = programdir
self.subjects = []
self.getSubjectList()
def isSubject(self,prospect):
prospect = str(prospect)
if not os.path.isdir(prospect):
return False
subdirlist = os.listdir(prospect)
foundmeshes = 0
for mfile in subdirlist:
if 'resliced_mesh' in mfile:
foundmeshes += 1
if foundmeshes == 14:
return True
return False
def setSubjectParentDir(self,path):
path = str(path)
if not os.path.isdir(path):
return False
dirlist = os.listdir(path)
for prospect in dirlist:
if self.isSubject(path +'/'+ prospect):
self.subjectParentDir = path
return True
return False
def getSubjectList(self):
del self.subjects[:]
slist = '['
for subject in os.listdir(str(self.subjectParentDir)):
if self.isSubject(self.subjectParentDir +'/'+ subject):
slist += '"' + subject + '",'
self.subjects.append(subject)
slist = slist[:-1] + ']'
return slist
def getCurrentSubject(self,index):
if (len(self.subjects)) < 1:
self.getSubjectList()
return self.subjectParentDir +'/'+ self.subjects[int(index)] +'/'
dirmanager = dirmanager(os.getcwd())
app = Flask(__name__)
@app.route('/')
def home():
return send_from_directory(dirmanager.programdir,'index.html')
@app.route('/mesh/<subject>/<roi>')
def mesh(subject,roi):
if 'resliced_mesh' in roi:
#print(roi,subject,dirmanager.getCurrentSubject(subject))
return send_from_directory(dirmanager.getCurrentSubject(subject), roi)
return 'permission denied'
@app.route('/subjects')
def subjects():
return dirmanager.getSubjectList()
@app.route('/scripts/<path>')
def scripts(path):
if path in ['main.js','math.js']:
return send_from_directory(dirmanager.programdir,path)
return 'permission denied'
@app.route('/change',methods=['POST','GET'])
def change():
newpath = str(request.args.get('newdir'))
if dirmanager.setSubjectParentDir(newpath):
response = 'Directory changed to ' + newpath
else:
response = newpath + ' is not a directory with enigma data.'
print(response)
return response
if __name__ == '__main__':
app.run(debug=False)