comparison 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
comparison
equal deleted inserted replaced
1:9f7e56f56079 2:9e8f5f220917
23 available only in some cases) : 23 available only in some cases) :
24 24
25 If there is an action value into data, then this one is ignored. 25 If there is an action value into data, then this one is ignored.
26 26
27 Outputs : 27 Outputs :
28 - output.json data file 28 - output.json data file (jsonoutput_filepath)
29 - 1 other file in following cases : 29 - 1 other file in following cases :
30 - experiment.xls file 30 - experiment.xls file
31 if 'action' == get_vpz_experiment, post_vpz_experiment 31 if 'action' == get_vpz_experiment, post_vpz_experiment
32 - conditions.xls file 32 - conditions.xls file
33 if 'action' == get_vpz_report_conditions, 33 if 'action' == get_vpz_report_conditions,
40 40
41 import argparse 41 import argparse
42 import json 42 import json
43 import erecord.api.erecord as erecord_api 43 import erecord.api.erecord as erecord_api
44 from erecord.api.cmn.views_mixins import ActionViewMixin 44 from erecord.api.cmn.views_mixins import ActionViewMixin
45 from erecord.api.cmn.utils.errors import build_error_content
46
45 import os 47 import os
46 import shutil 48 import shutil
47 from erecord.api.cmn.utils.dir_and_file import create_dir_if_absent
48 from erecord.api.cmn.configs.config import PROJECT_HOME
49 from erecord.api.cmn.configs.config import out_path
50 49
51 PM = "[main_file.py]" 50 PM = "[main_file.py]"
52
53 jsonoutput_filepath = os.path.join(out_path, "output.json") # tool.xml uses it
54 51
55 r = dict() 52 r = dict()
56 53
57 import sys 54 import sys
58 if MAIN_DEBUG: r["sys.path"] = sys.path # debug 55 if MAIN_DEBUG: r["sys.path"] = sys.path # debug
59 if MAIN_DEBUG: r["sys.argv"] = sys.argv # debug 56 if MAIN_DEBUG: r["sys.argv"] = sys.argv # debug
60 if MAIN_DEBUG: r["out_path"] = out_path # debug
61 57
62 data = dict() 58 data = dict()
63 json_response = dict() 59 json_response = dict()
64
65 create_dir_if_absent(PROJECT_HOME) # required
66 60
67 try : 61 try :
68 parser = argparse.ArgumentParser() 62 parser = argparse.ArgumentParser()
69 63
70 # -action 64 # -action
113 data['experimentfile'] = args.experimentfile 107 data['experimentfile'] = args.experimentfile
114 108
115 data['action'] = action 109 data['action'] = action
116 110
117 r["data"] = data 111 r["data"] = data
118 r_init = erecord_api.init() 112
113 # default configuration + maybe some modifications
114 config = erecord_api.conf() # default (vle-2.0.0 version)
115 config.DB_add_vpz(vpz_id=1312, vpzname="wwdm.vpz", pkgname="wwdm")
116 if MAIN_DEBUG: r["config"] = config.get_as_dict() # debug
117
118 r_init = erecord_api.init(config)
119 if MAIN_DEBUG: r["init"] = r_init # debug 119 if MAIN_DEBUG: r["init"] = r_init # debug
120 response = erecord_api.action(data) 120
121 response = erecord_api.action(config, data)
121 json_response = json.loads(response) 122 json_response = json.loads(response)
122 123
123 # Restitution : file (experiment.xls, conditions.xls, report.zip) 124 # Restitution : file (experiment.xls, conditions.xls, report.zip)
125 # Note :
126 # tool.xml command "touch" the file (in case of failed to be copied here)
127 # for it to exist (even if empty) => able to be found
124 if action in ['get_vpz_experiment', 'post_vpz_experiment', 128 if action in ['get_vpz_experiment', 'post_vpz_experiment',
125 'get_vpz_report_conditions', 'post_vpz_report_conditions', 129 'get_vpz_report_conditions', 'post_vpz_report_conditions',
126 'get_vpz_report', 'post_vpz_report']: 130 'get_vpz_report', 'post_vpz_report']:
131 try:
132 filename = json_response["outputfile_name"]
133 outputfile_path = json_response["outputfile_path"]
134 shutil.copyfile(src=outputfile_path,
135 dst=os.path.join(config.out_path,filename))
136 # tool.xml uses them
127 137
128 filename = json_response["outputfile_name"] 138 if not MAIN_DEBUG: # some response information not kept
129 outputfile_path = json_response["outputfile_path"] 139 for k in ('outputfile_name', 'outputfile_path', 'zip_file_path'):
130 shutil.copyfile(src=outputfile_path, 140 if k in json_response.keys(): del(json_response[k])
131 dst=os.path.join(out_path,filename)) # tool.xml uses them
132 141
133 if not MAIN_DEBUG: # some response information not kept 142 except Exception as e :
134 for k in ('outputfile_name', 'outputfile_path', 'zip_file_path'): 143
135 if k in json_response.keys(): 144 msg = PM+"[second file "
136 del(json_response[k]) 145 if "outputfile_name" in json_response.keys() :
146 msg = "('"+ json_response["outputfile_name"] + "')"
147 msg = " restitution]"
148 cnt = build_error_content(exception=e, errormsg=msg)
149 json_response["error PLUS"] = str(cnt)
137 150
138 except Exception as e : 151 except Exception as e :
139 152
140 response = erecord_api.error_case(data=data, msg=PM, e=e) 153 response = erecord_api.error_case(data=data, msg=PM, e=e)
141 json_response = json.loads(response) 154 json_response = json.loads(response)
142 155
143 r["response"] = json_response 156 r["response"] = json_response
144 157
145 # Restitution : json file 158 # Restitution : json file
159 jsonoutput_filepath = os.path.join(config.out_path, config.jsonoutput_filename)
146 with open(jsonoutput_filepath, "w") as outfile: 160 with open(jsonoutput_filepath, "w") as outfile:
147 json.dump(r, outfile) 161 json.dump(r, outfile)
148 162