Commit 71da54d6 authored by HERBERT Ryan's avatar HERBERT Ryan

controllers/admin.py scripts/retrieve_user_data.py moved functionnality

Retrieve user data is now no longer a route, due to locking when running
such a long controller method
parent 69aad7ac
python web2py/web2py.py -S vidjil -M -R "applications/vidjil/scripts/retrieve_user_data.py" -A "$1"
......@@ -217,43 +217,3 @@ def repair():
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def get_files():
import tarfile
if auth.is_admin():
user_id = request.vars['id']
base_query = ((db.auth_user.id == user_id)
&(db.auth_membership.user_id == db.auth_user.id)
&(db.auth_group.id == db.auth_membership.group_id)
&(db.auth_permission.group_id == db.auth_group.id)
&(db.auth_permission.table_name == "patient")
&(db.patient.id == db.auth_permission.record_id))
query = db( base_query &(db.fused_file.sample_set_id == db.patient.sample_set_id))
log.info(query._select(db.fused_file.fused_file))
fused_files = query.select(db.fused_file.fused_file.with_alias('filename'))
log.info(fused_files)
query = db(base_query & (db.analysis_file.sample_set_id == db.patient.sample_set_id))
log.info(query._select(db.analysis_file.analysis_file))
analysis_files = query.select(db.analysis_file.analysis_file.with_alias('filename'))
sequence_base_query = (base_query
& (db.patient.sample_set_id == db.sample_set_membership.sample_set_id)
& (db.sample_set_membership.sequence_file_id == db.sequence_file.id)
)
log.info(db(sequence_base_query)._select(db.sequence_file.data_file))
sequence_files = db(sequence_base_query).select(db.sequence_file.data_file.with_alias('filename'))
log.info(sequence_files)
query = db(sequence_base_query & (db.results_file.sequence_file_id == db.sequence_file.id))
log.info(query._select(db.results_file.data_file))
results_files = query.select(db.results_file.data_file.with_alias('filename'))
log.info(results_files)
with tarfile.open("/mnt/result/user_files.tar.gz", "w:gz") as tar:
for file_list in [(fused_files, defs.DIR_RESULTS), (analysis_files, defs.DIR_RESULTS), (sequence_files, defs.DIR_SEQUENCES), (results_files, defs.DIR_RESULTS)]:
for my_file in file_list[0]:
tar.add(file_list[1] + my_file.filename)
from __future__ import print_function
import sys
import tarfile
if sys.argv[1] == "-h" or sys.argv[1] == "--help" or sys.argv[1] is None:
print("Usage: %s <user id>\n\nRetrieve user's files (tar.gz format)." % sys.argv[0])
exit(1)
user_id = sys.argv[1]
base_query = ((db.auth_user.id == user_id)
&(db.auth_membership.user_id == db.auth_user.id)
&(db.auth_group.id == db.auth_membership.group_id)
&(db.auth_permission.group_id == db.auth_group.id)
&(db.auth_permission.table_name == "patient")
&(db.patient.id == db.auth_permission.record_id))
query = db( base_query &(db.fused_file.sample_set_id == db.patient.sample_set_id))
fused_files = query.select(db.fused_file.fused_file.with_alias('filename'), distinct=True)
query = db(base_query & (db.analysis_file.sample_set_id == db.patient.sample_set_id))
analysis_files = query.select(db.analysis_file.analysis_file.with_alias('filename'), distinct=True)
sequence_base_query = (base_query
& (db.patient.sample_set_id == db.sample_set_membership.sample_set_id)
& (db.sample_set_membership.sequence_file_id == db.sequence_file.id)
)
sequence_files = db(sequence_base_query).select(db.sequence_file.data_file.with_alias('filename'), distinct=True)
query = db(sequence_base_query & (db.results_file.sequence_file_id == db.sequence_file.id))
results_files = query.select(db.results_file.data_file.with_alias('filename'), distinct=True)
with tarfile.open("/mnt/result/user_files.tar.gz", "w:gz") as tar:
for file_list in [(fused_files, defs.DIR_RESULTS), (analysis_files, defs.DIR_RESULTS), (sequence_files, defs.DIR_SEQUENCES), (results_files, defs.DIR_RESULTS)]:
for my_file in file_list[0]:
if my_file.filename is not None:
tar.add(file_list[1] + my_file.filename)
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