Commit 11040c9f authored by Marc Duez's avatar Marc Duez

server.py : custom result file controller

parent a44b0df9
......@@ -151,7 +151,40 @@ def get_data():
"message" : "default/get_data : " + error}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
#########################################################################
def get_custom_data():
import time
from subprocess import Popen, PIPE, STDOUT
if not auth.user :
res = {"redirect" : URL('default', 'user', args='login', scheme=True, host=True)} #TODO _next
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
error = ""
if not "custom" in request.vars :
error += "no file selected, "
else:
for id in request.vars["custom"] :
sequence_file_id = db.results_file[id].sequence_file_id
patient_id =db.sequence_file[sequence_file_id].patient_id
if not auth.has_permission('admin', 'patient', patient_id) and \
not auth.has_permission('read', 'patient', patient_id):
error += "you do not have permission to consult this patient ("+str(patient_id)+")"
if error == "" :
data = custom_fuse(request.vars["custom"])
res = {"success" : "plop",
"message" : "default/get_data : "+ ",".join(request.vars["custom"])}
return gluon.contrib.simplejson.dumps(data, separators=(',',':'))
else :
res = {"success" : "false",
"message" : "default/get_custom_data : " + error}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
#########################################################################
## return .analysis file
# need patient_id, config_id
......
......@@ -99,6 +99,37 @@ def info():
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def custom():
if request.vars["config_id"] and request.vars["config_id"] != "-1" :
config_id = long(request.vars["config_id"])
config_name = db.config[request.vars["config_id"]].name
config = True
else:
config_id = -1
config = False
if config :
query = db(
(auth.accessible_query('read', db.patient) | auth.accessible_query('admin', db.patient) )
& (db.sequence_file.patient_id==db.patient.id)
& (db.results_file.sequence_file_id==db.sequence_file.id)
& (db.results_file.config_id==str(config_id) )
& (db.results_file.scheduler_task_id==db.scheduler_task.id)
& (db.scheduler_task.status=='COMPLETED')
).select(
orderby = db.sequence_file.patient_id|db.sequence_file.id|db.results_file.run_date,
groupby = db.sequence_file.id,
)
else:
query = []
return dict(query=query,
config_id=config_id,
config=config)
## return patient list
def index():
......
......@@ -276,6 +276,45 @@ def run_fuse(id_file, id_config, id_data, id_fuse, clean_before=True, clean_afte
return "SUCCESS"
def custom_fuse(file_list):
import time, datetime, sys, os.path, random
from subprocess import Popen, PIPE, STDOUT, os
random_id = random.randint(99999999,99999999999)
out_folder = defs.DIR_OUT_VIDJIL_ID % random_id
output_filename = "%06d" % random_id
cmd = "rm -rf "+out_folder
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
p.wait()
os.makedirs(out_folder)
fuse_log_file = open(out_folder+'/'+output_filename+'.fuse.log', 'w')
## fuse.py
output_file = out_folder+'/'+output_filename+'.fused'
files = ""
for id in file_list :
if db.results_file[id].data_file is not None :
files += defs.DIR_RESULTS + db.results_file[id].data_file + " "
cmd = "python "+defs.DIR_FUSE+"/fuse.py -o "+output_file+" -t 100 "+files
sys.stdout.flush()
p = Popen(cmd, shell=True, stdin=PIPE, stdout=fuse_log_file, stderr=STDOUT, close_fds=True)
(stdoutdata, stderrdata) = p.communicate()
fuse_filepath = os.path.abspath(output_file)
try:
f = open(fuse_filepath, 'rb')
data = gluon.contrib.simplejson.loads(f.read())
except IOError:
raise IOError
clean_cmd = "rm -rf " + out_folder
p = Popen(clean_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
p.wait()
return data
from gluon.scheduler import Scheduler
scheduler = Scheduler(db, dict(vidjil=run_vidjil,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment