comparison main_json.py @ 2:afc88ac8de69 draft

planemo upload for repository https://forgemia.inra.fr/nathalie.rousse/erecord-deploy/-/tree/main/galaxy-tools/erecord_json commit 2bd91617d46a1c454a7a167113cc605bdd1b3ff2-dirty
author siwaa
date Thu, 15 Feb 2024 14:44:16 +0000
parents 8a0659f23df7
children eb06af7c29a8
comparison
equal deleted inserted replaced
1:d87b8a1073ad 2:afc88ac8de69
21 A required action value must be included into data. 21 A required action value must be included into data.
22 - '-datafolder' parameter : datafolder file path (optional, 22 - '-datafolder' parameter : datafolder file path (optional,
23 available only in some cases) 23 available only in some cases)
24 24
25 Outputs : 25 Outputs :
26 - output.json data file 26 - output.json data file (jsonoutput_filepath)
27
27 """ 28 """
28 29
29 MAIN_DEBUG=False # True for more information returned 30 MAIN_DEBUG=False # True for more information returned
30 31
31 import argparse 32 import argparse
32 import json 33 import json
33 import erecord.api.erecord as erecord_api 34 import erecord.api.erecord as erecord_api
35
34 import os 36 import os
35 from erecord.api.cmn.utils.dir_and_file import create_dir_if_absent
36 from erecord.api.cmn.configs.config import PROJECT_HOME
37 from erecord.api.cmn.configs.config import out_path
38 37
39 PM = "[main_json.py]" 38 PM = "[main_json.py]"
40 39
41 UNACCEPTED_ACTIONS_LIST = ['get_vpz_experiment', 'post_vpz_experiment', 40 UNACCEPTED_ACTIONS_LIST = ['get_vpz_experiment', 'post_vpz_experiment',
42 'get_vpz_report_conditions', 'post_vpz_report_conditions', 41 'get_vpz_report_conditions', 'post_vpz_report_conditions',
43 'get_vpz_report', 'post_vpz_report'] 42 'get_vpz_report', 'post_vpz_report']
44 43
45 jsonoutput_filepath = os.path.join(out_path, "output.json") # tool.xml uses it
46
47 r = dict() 44 r = dict()
48 45
49 import sys 46 import sys
50 if MAIN_DEBUG: r["sys.path"] = sys.path # debug 47 if MAIN_DEBUG: r["sys.path"] = sys.path # debug
51 if MAIN_DEBUG: r["sys.argv"] = sys.argv # debug 48 if MAIN_DEBUG: r["sys.argv"] = sys.argv # debug
52 if MAIN_DEBUG: r["out_path"] = out_path # debug
53 49
54 data = dict() 50 data = dict()
55 json_response = dict() 51 json_response = dict()
56
57 create_dir_if_absent(PROJECT_HOME) # required
58 52
59 try : 53 try :
60 parser = argparse.ArgumentParser() 54 parser = argparse.ArgumentParser()
61 parser.add_argument("-data", type=str, help="data json file path") 55 parser.add_argument("-data", type=str, help="data json file path")
62 parser.add_argument("-datafolder", type=str, help="datafolder file path") 56 parser.add_argument("-datafolder", type=str, help="datafolder file path")
84 warn = "Unaccepted action '"+a+"' => action enforced to 'help'" 78 warn = "Unaccepted action '"+a+"' => action enforced to 'help'"
85 r["warning"] = warn 79 r["warning"] = warn
86 data["action"] = 'help' 80 data["action"] = 'help'
87 81
88 r["data"] = data 82 r["data"] = data
89 r_init = erecord_api.init() 83
84 # default configuration + maybe some modifications
85 config = erecord_api.conf() # default (vle-2.0.0 version)
86 config.DB_add_vpz(vpz_id=1312, vpzname="wwdm.vpz", pkgname="wwdm")
87 if MAIN_DEBUG: r["config"] = config.get_as_dict() # debug
88
89 r_init = erecord_api.init(config)
90 if MAIN_DEBUG: r["init"] = r_init # debug 90 if MAIN_DEBUG: r["init"] = r_init # debug
91 response = erecord_api.action(data) 91
92 response = erecord_api.action(config, data)
92 json_response = json.loads(response) 93 json_response = json.loads(response)
93 94
94 except Exception as e : 95 except Exception as e :
95 96
96 response = erecord_api.error_case(data=data, msg=PM, e=e) 97 response = erecord_api.error_case(data=data, msg=PM, e=e)
97 json_response = json.loads(response) 98 json_response = json.loads(response)
98 99
99 r["response"] = json_response 100 r["response"] = json_response
100 101
101 # Restitution : json file 102 # Restitution : json file
103 jsonoutput_filepath = os.path.join(config.out_path, config.jsonoutput_filename)
102 with open(jsonoutput_filepath, "w") as outfile: 104 with open(jsonoutput_filepath, "w") as outfile:
103 json.dump(r, outfile) 105 json.dump(r, outfile)
104 106