Mercurial > repos > siwaa > erecord_file
diff main_file.py @ 2:9e8f5f220917 draft
planemo upload for repository https://forgemia.inra.fr/nathalie.rousse/erecord-deploy/-/tree/main/galaxy-tools/erecord_file commit 2bd91617d46a1c454a7a167113cc605bdd1b3ff2-dirty
author | siwaa |
---|---|
date | Thu, 15 Feb 2024 14:44:47 +0000 |
parents | 27e7e4d38e44 |
children | aa5c088856c8 |
line wrap: on
line diff
--- a/main_file.py Wed Dec 13 21:45:47 2023 +0000 +++ b/main_file.py Thu Feb 15 14:44:47 2024 +0000 @@ -25,7 +25,7 @@ If there is an action value into data, then this one is ignored. Outputs : - - output.json data file + - output.json data file (jsonoutput_filepath) - 1 other file in following cases : - experiment.xls file if 'action' == get_vpz_experiment, post_vpz_experiment @@ -42,28 +42,22 @@ import json import erecord.api.erecord as erecord_api from erecord.api.cmn.views_mixins import ActionViewMixin +from erecord.api.cmn.utils.errors import build_error_content + import os import shutil -from erecord.api.cmn.utils.dir_and_file import create_dir_if_absent -from erecord.api.cmn.configs.config import PROJECT_HOME -from erecord.api.cmn.configs.config import out_path PM = "[main_file.py]" -jsonoutput_filepath = os.path.join(out_path, "output.json") # tool.xml uses it - r = dict() import sys if MAIN_DEBUG: r["sys.path"] = sys.path # debug if MAIN_DEBUG: r["sys.argv"] = sys.argv # debug -if MAIN_DEBUG: r["out_path"] = out_path # debug data = dict() json_response = dict() -create_dir_if_absent(PROJECT_HOME) # required - try : parser = argparse.ArgumentParser() @@ -115,25 +109,44 @@ data['action'] = action r["data"] = data - r_init = erecord_api.init() + + # default configuration + maybe some modifications + config = erecord_api.conf() # default (vle-2.0.0 version) + config.DB_add_vpz(vpz_id=1312, vpzname="wwdm.vpz", pkgname="wwdm") + if MAIN_DEBUG: r["config"] = config.get_as_dict() # debug + + r_init = erecord_api.init(config) if MAIN_DEBUG: r["init"] = r_init # debug - response = erecord_api.action(data) + + response = erecord_api.action(config, data) json_response = json.loads(response) - - # Restitution : file (experiment.xls, conditions.xls, report.zip) - if action in ['get_vpz_experiment', 'post_vpz_experiment', - 'get_vpz_report_conditions', 'post_vpz_report_conditions', - 'get_vpz_report', 'post_vpz_report']: - filename = json_response["outputfile_name"] - outputfile_path = json_response["outputfile_path"] - shutil.copyfile(src=outputfile_path, - dst=os.path.join(out_path,filename)) # tool.xml uses them + # Restitution : file (experiment.xls, conditions.xls, report.zip) + # Note : + # tool.xml command "touch" the file (in case of failed to be copied here) + # for it to exist (even if empty) => able to be found + if action in ['get_vpz_experiment', 'post_vpz_experiment', + 'get_vpz_report_conditions', 'post_vpz_report_conditions', + 'get_vpz_report', 'post_vpz_report']: + try: + filename = json_response["outputfile_name"] + outputfile_path = json_response["outputfile_path"] + shutil.copyfile(src=outputfile_path, + dst=os.path.join(config.out_path,filename)) + # tool.xml uses them - if not MAIN_DEBUG: # some response information not kept - for k in ('outputfile_name', 'outputfile_path', 'zip_file_path'): - if k in json_response.keys(): - del(json_response[k]) + if not MAIN_DEBUG: # some response information not kept + for k in ('outputfile_name', 'outputfile_path', 'zip_file_path'): + if k in json_response.keys(): del(json_response[k]) + + except Exception as e : + + msg = PM+"[second file " + if "outputfile_name" in json_response.keys() : + msg = "('"+ json_response["outputfile_name"] + "')" + msg = " restitution]" + cnt = build_error_content(exception=e, errormsg=msg) + json_response["error PLUS"] = str(cnt) except Exception as e : @@ -143,6 +156,7 @@ r["response"] = json_response # Restitution : json file +jsonoutput_filepath = os.path.join(config.out_path, config.jsonoutput_filename) with open(jsonoutput_filepath, "w") as outfile: json.dump(r, outfile)