changeset 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 9f7e56f56079
children aa5c088856c8
files erecord_file.xml main_file.py
diffstat 2 files changed, 48 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/erecord_file.xml	Wed Dec 13 21:45:47 2023 +0000
+++ b/erecord_file.xml	Thu Feb 15 14:44:47 2024 +0000
@@ -5,7 +5,10 @@
   <requirements>
 
     <!-- singularity -->
-    <container type="singularity">oras://registry.forgemia.inra.fr/nathalie.rousse/erecord-deploy/erecord_rep0_vle2:53e4840cd66e45761db955f69203284761fd6df8</container>
+    <container type="singularity">oras://registry.forgemia.inra.fr/nathalie.rousse/erecord-deploy/rep_recordb:9d6ea1defd50dd63fe036a7545a9ea527572192e</container>
+
+    <!-- image locale -->
+    <!-- container type="singularity">/home/nrousse/workspace_git/SIWAA_regroup/erecord-deploy/containers/_fab_SIMG/rep_recordb.simg</container-->
 
   </requirements>
 
@@ -29,16 +32,22 @@
     cp WS/OUT/output.json ${output_json};
 
     #if $request_condition.action_name == 'get_vpz_experiment':
+        touch WS/OUT/experiment.xls;
         cp WS/OUT/experiment.xls ${experiment};
     #elif $request_condition.action_name == 'post_vpz_experiment':
+        touch WS/OUT/experiment.xls;
         cp WS/OUT/experiment.xls ${experiment};
     #elif $request_condition.action_name == 'get_vpz_report_conditions':
+        touch WS/OUT/conditions.xls;
         cp WS/OUT/conditions.xls ${conditions};
     #elif $request_condition.action_name == 'post_vpz_report_conditions':
+        touch WS/OUT/conditions.xls;
         cp WS/OUT/conditions.xls ${conditions};
     #elif $request_condition.action_name == 'get_vpz_report':
+        touch WS/OUT/report.zip;
         cp WS/OUT/report.zip ${report};
     #elif $request_condition.action_name == 'post_vpz_report':
+        touch WS/OUT/report.zip;
         cp WS/OUT/report.zip ${report};
     #end if
 
--- 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)