]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Change the way of we execute user script files
authorAndré Ribes <andre.ribes@edf.fr>
Wed, 16 Nov 2011 10:23:58 +0000 (11:23 +0100)
committerAndré Ribes <andre.ribes@edf.fr>
Wed, 16 Nov 2011 10:23:58 +0000 (11:23 +0100)
.gitignore
examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py
examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py
resources/ADAOSchemaCatalog.xml
src/daSalome/daYacsSchemaCreator/methods.py

index fc035428e4312d2836d94c9cd05ef0b386dec68d..9ff4f6a8135050fc1beb4bc2c662177a42cd065f 100644 (file)
@@ -48,3 +48,4 @@ src/daSalome/daGUI/daUtils/Makefile.in
 git_diff.log
 git_fetch.log
 update.log
+binary_archive.log
index a13bb2dea1842a9eca2bf34a529f0846bd65f732..2816eb28434317d8d50c3e4ef9dcbd4187e00824 100644 (file)
@@ -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
 #
index 651b6028528ab3d6cd4a22cbd46e1c3bb8210f59..8e3a0a1d5d0de73966aaaffa476ac228a62a0171 100644 (file)
@@ -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
 #
index a58fd4992116abcf78d3c1d7b8da9669307bfacf..6ce262294c910e5842629de1ae1a65887ab7ca22 100644 (file)
@@ -194,8 +194,21 @@ print "Matrix is", matrix
   <inline name="CreateNumpyMatrixFromScript">
     <script><code><![CDATA[
 print "Entering in CreateNumpyMatrixFromScript"
-execfile(script)
 type = "Matrix"
+
+# Get file path and filename
+import sys
+import os
+filepath = os.path.dirname(script)
+filename = os.path.basename(script)
+module_name = os.path.splitext(filename)[0]
+sys.path.insert(0,filepath)
+
+# Import script
+__import__(module_name)
+user_script_module = sys.modules[module_name]
+
+# Get Data from script
 ]]></code></script>
     <inport name="script" type="string"/>
     <outport name="type" type="string"/>
@@ -217,8 +230,21 @@ print "Vector is", vector
   <inline name="CreateNumpyVectorFromScript">
     <script><code><![CDATA[
 print "Entering in CreateNumpyVectorFromScript"
-execfile(script)
 type = "Vector"
+
+# Get file path and filename
+import sys
+import os
+filepath = os.path.dirname(script)
+filename = os.path.basename(script)
+module_name = os.path.splitext(filename)[0]
+sys.path.insert(0,filepath)
+
+# Import script
+__import__(module_name)
+user_script_module = sys.modules[module_name]
+
+# Get Data from script
 ]]></code></script>
     <inport name="script" type="string"/>
     <outport name="type" type="string"/>
@@ -259,7 +285,20 @@ result = None
   <inline name="CreateDictFromScript">
     <script><code><![CDATA[
 print "Entering in CreateDictFromScript"
-execfile(script)
+
+# Get file path and filename
+import sys
+import os
+filepath = os.path.dirname(script)
+filename = os.path.basename(script)
+module_name = os.path.splitext(filename)[0]
+sys.path.insert(0,filepath)
+
+# Import script
+__import__(module_name)
+user_script_module = sys.modules[module_name]
+
+# Get Data from script
 ]]></code></script>
     <inport name="script" type="string"/>
   </inline>
@@ -267,7 +306,20 @@ execfile(script)
   <inline name="UserDataInitFromScript">
     <script><code><![CDATA[
 print "Entering in UserDataInitFromScript"
-execfile(script)
+
+# Get file path and filename
+import sys
+import os
+filepath = os.path.dirname(script)
+filename = os.path.basename(script)
+module_name = os.path.splitext(filename)[0]
+sys.path.insert(0,filepath)
+
+# Import script
+__import__(module_name)
+user_script_module = sys.modules[module_name]
+
+# Get Data from script
 ]]></code></script>
     <inport name="script" type="string"/>
     <outport name="init_data" type="pyobj"/>
index ed7f65a4e267130c91c0d5e18d1399421ab6a7ec..373603f44bc042e334d2130b4e0b2cd8fbd198b5 100644 (file)
@@ -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":