Mercurial > repos > siwaa > erecord_json
comparison main_json.py @ 3:eb06af7c29a8 draft default tip
planemo upload for repository https://forgemia.inra.fr/nathalie.rousse/erecord-deploy/-/tree/main/galaxy-tools/erecord_json commit 490623122691651ac91c33d75ea1898189be7512-dirty
| author | siwaa |
|---|---|
| date | Thu, 15 Feb 2024 15:24:41 +0000 |
| parents | afc88ac8de69 |
| children |
comparison
equal
deleted
inserted
replaced
| 2:afc88ac8de69 | 3:eb06af7c29a8 |
|---|---|
| 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 (jsonoutput_filepath) | 26 - output.json data file (jsonoutput_filepath) |
| 27 | |
| 28 """ | 27 """ |
| 29 | 28 |
| 30 MAIN_DEBUG=False # True for more information returned | 29 MAIN_DEBUG=False # True for more information returned |
| 31 | 30 |
| 32 import argparse | 31 import argparse |
| 47 if MAIN_DEBUG: r["sys.path"] = sys.path # debug | 46 if MAIN_DEBUG: r["sys.path"] = sys.path # debug |
| 48 if MAIN_DEBUG: r["sys.argv"] = sys.argv # debug | 47 if MAIN_DEBUG: r["sys.argv"] = sys.argv # debug |
| 49 | 48 |
| 50 data = dict() | 49 data = dict() |
| 51 json_response = dict() | 50 json_response = dict() |
| 51 | |
| 52 # default configuration + maybe some modifications | |
| 53 config = erecord_api.conf() # default (vle-2.0.0 version) | |
| 54 config.DB_add_vpz(vpz_id=1312, vpzname="wwdm.vpz", pkgname="wwdm") | |
| 52 | 55 |
| 53 try : | 56 try : |
| 54 parser = argparse.ArgumentParser() | 57 parser = argparse.ArgumentParser() |
| 55 parser.add_argument("-data", type=str, help="data json file path") | 58 parser.add_argument("-data", type=str, help="data json file path") |
| 56 parser.add_argument("-datafolder", type=str, help="datafolder file path") | 59 parser.add_argument("-datafolder", type=str, help="datafolder file path") |
| 79 r["warning"] = warn | 82 r["warning"] = warn |
| 80 data["action"] = 'help' | 83 data["action"] = 'help' |
| 81 | 84 |
| 82 r["data"] = data | 85 r["data"] = data |
| 83 | 86 |
| 84 # default configuration + maybe some modifications | 87 # configuration |
| 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 if MAIN_DEBUG: r["config"] = config.get_as_dict() # debug |
| 88 | 89 |
| 89 r_init = erecord_api.init(config) | 90 r_init = erecord_api.init(config) |
| 90 if MAIN_DEBUG: r["init"] = r_init # debug | 91 if MAIN_DEBUG: r["init"] = r_init # debug |
| 91 | 92 |
| 97 response = erecord_api.error_case(data=data, msg=PM, e=e) | 98 response = erecord_api.error_case(data=data, msg=PM, e=e) |
| 98 json_response = json.loads(response) | 99 json_response = json.loads(response) |
| 99 | 100 |
| 100 r["response"] = json_response | 101 r["response"] = json_response |
| 101 | 102 |
| 102 # Restitution : json file | 103 try : |
| 103 jsonoutput_filepath = os.path.join(config.out_path, config.jsonoutput_filename) | 104 # Restitution : json file |
| 104 with open(jsonoutput_filepath, "w") as outfile: | 105 jsonoutput_filepath = os.path.join(config.out_path, |
| 105 json.dump(r, outfile) | 106 config.jsonoutput_filename) |
| 107 with open(jsonoutput_filepath, "w") as outfile: | |
| 108 json.dump(r, outfile) | |
| 106 | 109 |
| 110 except : | |
| 111 print(PM, " -- error when trying to open output json file --") | |
| 112 |
