From 81352f0edf189c5bf3bf071c644b68363c7d29d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Ribes?= Date: Wed, 16 Nov 2011 11:23:58 +0100 Subject: [PATCH] Change the way of we execute user script files --- .gitignore | 1 + .../Script_ObservationOperator_H.py | 1 - .../Script_UserPostAnalysis.py | 1 - resources/ADAOSchemaCatalog.xml | 60 +++++++++++++++++-- src/daSalome/daYacsSchemaCreator/methods.py | 32 ++++++++-- 5 files changed, 85 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index fc03542..9ff4f6a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ src/daSalome/daGUI/daUtils/Makefile.in git_diff.log git_fetch.log update.log +binary_archive.log diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py index a13bb2d..2816eb2 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py @@ -30,7 +30,6 @@ __author__ = "Jean-Philippe ARGAUD" # # ============================================================================== # -import sys, os ; sys.path.insert(0,os.path.dirname(os.path.abspath(__file__))) import Physical_simulation_functions import numpy, logging # diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py index 651b602..8e3a0a1 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py @@ -30,7 +30,6 @@ __author__ = "Jean-Philippe ARGAUD" # # ============================================================================== # -import sys, os ; sys.path.insert(0,os.path.dirname(os.path.abspath(__file__))) from Physical_data_and_covariance_matrices import True_state import numpy # diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index a58fd49..6ce2622 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -194,8 +194,21 @@ print "Matrix is", matrix @@ -217,8 +230,21 @@ print "Vector is", vector @@ -259,7 +285,20 @@ result = None @@ -267,7 +306,20 @@ execfile(script) diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index ed7f65a..373603f 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -119,6 +119,9 @@ def create_yacs_proc(study_config): else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) + back_node_script = back_node.getScript() + back_node_script += key + " = user_script_module." + key + "\n" + back_node.setScript(back_node_script) proc.edAddChild(back_node) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) @@ -153,6 +156,9 @@ def create_yacs_proc(study_config): else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) + back_node_script = back_node.getScript() + back_node_script += key + " = user_script_module." + key + "\n" + back_node.setScript(back_node_script) proc.edAddChild(back_node) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) @@ -189,6 +195,9 @@ def create_yacs_proc(study_config): else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) + back_node_script = back_node.getScript() + back_node_script += key + " = user_script_module." + key + "\n" + back_node.setScript(back_node_script) proc.edAddChild(back_node) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) @@ -245,7 +254,15 @@ def create_yacs_proc(study_config): logging.fatal("Exception in opening function script file : " + script_filename) traceback.print_exc() sys.exit(1) - opt_script_node.setScript(script_str.read()) + node_script = "#-*-coding:iso-8859-1-*-\n" + node_script += "import sys, os \n" + if base_repertory != "": + node_script += "filepath = \"" + base_repertory + "\"\n" + else: + node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n" + node_script += "sys.path.insert(0,os.path.dirname(filepath))\n" + node_script += script_str.read() + opt_script_node.setScript(node_script) opt_script_node.edAddInputPort("computation", t_param_input) opt_script_node.edAddOutputPort("result", t_param_output) @@ -310,9 +327,16 @@ def create_yacs_proc(study_config): logging.fatal("Exception in opening analysis file : " + str(analysis_config["Data"])) traceback.print_exc() sys.exit(1) - file_text = analysis_file.read() - final_script = default_script + file_text - analysis_node.setScript(final_script) + node_script = "#-*-coding:iso-8859-1-*-\n" + node_script += "import sys, os \n" + if base_repertory != "": + node_script += "filepath = \"" + base_repertory + "\"\n" + else: + node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n" + node_script += "sys.path.insert(0,os.path.dirname(filepath))\n" + node_script += default_script + node_script += analysis_file.read() + analysis_node.setScript(node_script) proc.edAddChild(analysis_node) proc.edAddCFLink(compute_bloc, analysis_node) if AlgoType[study_config["Algorithm"]] == "Optim": -- 2.39.2