Mercurial > repos > siwaa > gama_desc
comparison desc.py @ 0:23b15c0eabff draft default tip
planemo upload for repository https://forgemia.inra.fr/nathalie.rousse/use/-/tree/gama/GAMA_DESC/galaxy-tools commit 6b9b95de1fe709f27a28d83797f81e91469edf79-dirty
| author | siwaa |
|---|---|
| date | Mon, 18 Nov 2024 13:57:51 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:23b15c0eabff |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # coding: utf-8 | |
| 3 | |
| 4 #----------------------------------------------------------------- | |
| 5 __author__ = "Nathalie Rousse (nathalie.rousse@inrae.fr)" | |
| 6 __copyright__ = "Copyright (C) 2024, Inrae (https://www.inrae.fr)" | |
| 7 __license__ = "MIT" | |
| 8 #----------------------------------------------------------------- | |
| 9 | |
| 10 import json | |
| 11 | |
| 12 # Produces a description JSON data from a GAML model file | |
| 13 | |
| 14 ############################################################################### | |
| 15 | |
| 16 def make_json_experiments_by_types(gaml_file_path): | |
| 17 | |
| 18 # experiments contains lists of experiment names, by type | |
| 19 experiments = { "gui": [], "batch": [], "test": [], "memorize": [] } | |
| 20 | |
| 21 with open(gaml_file_path, 'r') as f: | |
| 22 lines = f.readlines() | |
| 23 | |
| 24 for line in lines: | |
| 25 experiment_name, type = None, None # default | |
| 26 line_kept = True # default | |
| 27 if "experiment" not in line : line_kept = False | |
| 28 if ("type " not in line and "type:" not in line) : line_kept = False | |
| 29 | |
| 30 if line_kept : | |
| 31 words = line.split() | |
| 32 if words[0] == 'experiment' : | |
| 33 experiment_name = words[1] | |
| 34 else: | |
| 35 line_kept = False | |
| 36 | |
| 37 if line_kept : | |
| 38 while " :" in line: | |
| 39 line = line.replace(" :", ":") | |
| 40 line = line.replace(":", ": ") | |
| 41 words = line.split() | |
| 42 for i,word in enumerate(words) : | |
| 43 if word == "type:" : | |
| 44 if words[i+1] in ("gui", "batch", "test", "memorize"): | |
| 45 type = words[i+1] | |
| 46 if line_kept and (experiment_name is not None) and (type is not None): | |
| 47 experiments[type].append(experiment_name) | |
| 48 | |
| 49 return experiments | |
| 50 | |
| 51 ############################################################################### | |
| 52 | |
| 53 GAML_FILE_PATH = "model.gaml" | |
| 54 DESC_JSON_FILE_PATH = "desc.json" | |
| 55 | |
| 56 try : | |
| 57 desc = dict() | |
| 58 experiments = make_json_experiments_by_types(gaml_file_path=GAML_FILE_PATH) | |
| 59 desc['experiments_by_types'] = experiments | |
| 60 print(desc) | |
| 61 with open(DESC_JSON_FILE_PATH, "w") as json_file: | |
| 62 json_file.write(json.dumps(desc)) | |
| 63 | |
| 64 except Exception as e : | |
| 65 errortype = type(e).__name__ | |
| 66 errordetails = e.args | |
| 67 print("ERROR:", errortype, errordetails) | |
| 68 | |
| 69 ############################################################################### |
