]> SALOME platform Git repositories - modules/hydrosolver.git/commitdiff
Salome HOME
Correction for Python3
authorYAUDOUIN <B61570@dsp0897933.atlas.edf.fr>
Fri, 15 Nov 2019 12:15:43 +0000 (13:15 +0100)
committerYAUDOUIN <B61570@dsp0897933.atlas.edf.fr>
Fri, 15 Nov 2019 12:15:43 +0000 (13:15 +0100)
src/salome_hydro/param_study/eficas/param_study_cata.py
src/salome_hydro/run_study/genjob.py
src/salome_hydro/run_study/launcher.py
src/salome_hydro/study.py

index ab9e09ca5ce43f469f7c4defdd8ac186179c1452..10d56cddddf8d22238dc83b5e45c33cef8132b4e 100644 (file)
@@ -26,19 +26,22 @@ def get_list_var_api(module):
 
     @param One of the modules of TELEMAC-MASCARET
     """
+    with open('dummy.cas', 'w') as f:
+        f.write('/Dummy steering file')
+
     if module == 'TELEMAC2D':
-        from TelApy.api.t2d import Telemac2d
+        from telapy.api.t2d import Telemac2d
         model = Telemac2d('dummy.cas')
     elif module == 'TELEMAC3D':
-        from TelApy.api.t3d import Telemac3d
+        from telapy.api.t3d import Telemac3d
         model = Telemac3d('dummy.cas')
     elif module == 'SISYPHE':
-        from TelApy.api.sis import Sisyphe
+        from telapy.api.sis import Sisyphe
         model = Sisyphe('dummy.cas')
     else:
         return ['No variable available']
 
-    varnames, _ = model.list_variables()
+    varnames, _ = model.list_variable()
     del(model)
     return sorted(varnames)
 
index 1781aa54e3db453c976641758dbd2939ec5ea587..89fdf5149bc7a1ffeba4e9363761cc0d63a6ee25 100644 (file)
@@ -14,6 +14,9 @@
 #
 #  You should have received a copy of the GNU General Public License
 #  along with SALOME HYDRO module.  If not, see <http://www.gnu.org/licenses/>.
+"""
+Script for launch a steering file via the jobmanager
+"""
 
 import os
 import tempfile
@@ -22,60 +25,63 @@ import glob
 
 import salome
 
-job_script_template = """#!/bin/sh
+JOB_SCRIPT_TEMPLATE = """#!/bin/sh
 
 . %(env_file)s
 runcode.py %(code)s %(cas)s --ncsize %(nbcore)d
+cd -
 """
 
 def generate_job(study_params, resource, telemac_root_dir, telemac_env_file,
                  nbcore, input_data_dir, result_dir):
-  """
-  Create a Launcher job using the parameters specified by the user.
-  """
-  # Generate job script
-  basename = os.path.basename(study_params["FICHIER_CAS"])
-  job_script = job_script_template % {"env_file": telemac_env_file,
-                                      "code": study_params["CODE"],
-                                      "cas": basename,
-                                      "nbcore": nbcore}
+    """
+    Create a Launcher job using the parameters specified by the user.
+    """
+    # Generate job script
+    basename = os.path.basename(study_params["FICHIER_CAS"])
+    job_script = JOB_SCRIPT_TEMPLATE % {"env_file": telemac_env_file,
+                                        "code": study_params["CODE"],
+                                        "cas": basename,
+                                        "nbcore": nbcore}
 
 
-  (fd, job_script_file) = tempfile.mkstemp(prefix = "job_" + basename + "_", suffix = ".sh")
-  os.close(fd)
-  f = open(job_script_file, "w")
-  f.write(job_script)
-  f.close()
+    (fd, job_script_file) = \
+            tempfile.mkstemp(prefix="job_" + basename + "_", suffix=".sh")
+    os.close(fd)
+    f = open(job_script_file, "w")
+    f.write(job_script)
+    f.close()
 
-  # Define job parameters
-  job_params = salome.JobParameters()
-  job_params.job_name = basename
-  job_params.job_type = "command"
-  job_params.job_file = job_script_file
-  input_files = glob.glob(os.path.join(input_data_dir, "*")) + [study_params["FICHIER_CAS"]]
-  input_files = list(set(input_files)) # Remove duplicates
-  job_params.in_files = input_files
-  job_params.out_files = []
-  job_params.result_directory = result_dir
+    # Define job parameters
+    job_params = salome.JobParameters()
+    job_params.job_name = basename
+    job_params.job_type = "command"
+    job_params.job_file = job_script_file
+    input_files = glob.glob(os.path.join(input_data_dir, "*")) \
+                  + [study_params["FICHIER_CAS"]]
+    input_files = list(set(input_files)) # Remove duplicates
+    job_params.in_files = input_files
+    job_params.out_files = []
+    job_params.result_directory = result_dir
 
-  # Define resource parameters
-  job_params.resource_required = salome.ResourceParameters()
-  job_params.resource_required.name = resource
-  job_params.resource_required.nb_proc = nbcore
+    # Define resource parameters
+    job_params.resource_required = salome.ResourceParameters()
+    job_params.resource_required.name = resource
+    job_params.resource_required.nb_proc = nbcore
 
-  # Generate name for the working directory
-  res_manager = salome.naming_service.Resolve("/ResourcesManager")
-  res_definition = res_manager.GetResourceDefinition(resource)
-  res_work_dir = res_definition.working_directory
-  if res_work_dir != "":
-      timestr = datetime.now().ctime()
-      timestr = timestr.replace('/', '_')
-      timestr = timestr.replace('-', '_')
-      timestr = timestr.replace(':', '_')
-      timestr = timestr.replace(' ', '_')
-      work_dir = res_work_dir + "/" + job_params.job_name + "_" + timestr
-      job_params.work_directory = work_dir
+    # Generate name for the working directory
+    res_manager = salome.naming_service.Resolve("/ResourcesManager")
+    res_definition = res_manager.GetResourceDefinition(resource)
+    res_work_dir = res_definition.working_directory
+    if res_work_dir != "":
+        timestr = datetime.now().ctime()
+        timestr = timestr.replace('/', '_')
+        timestr = timestr.replace('-', '_')
+        timestr = timestr.replace(':', '_')
+        timestr = timestr.replace(' ', '_')
+        work_dir = res_work_dir + "/" + job_params.job_name + "_" + timestr
+        job_params.work_directory = work_dir
 
-  # Create Launcher job
-  launcher = salome.naming_service.Resolve('/SalomeLauncher')
-  launcher.createJob(job_params)
+    # Create Launcher job
+    launcher = salome.naming_service.Resolve('/SalomeLauncher')
+    launcher.createJob(job_params)
index b1ee58c7197133cfdd9022392d9d4017c71a0e71..8edb96f7c0813101ada7e26d4cce68d99413ff15 100644 (file)
@@ -14,6 +14,9 @@
 #
 #  You should have received a copy of the GNU General Public License
 #  along with SALOME HYDRO module.  If not, see <http://www.gnu.org/licenses/>.
+"""
+Script for launch in terminal of a steering file
+"""
 
 import os
 import subprocess
@@ -51,8 +54,8 @@ def run_study(param_dict):
 
   # Run the code itself
   code = param_dict["CODE"]
-  cmd += "runcode.py -w %s %s %s" % \
-         (wrkdir, code, steering_filepath)
+  cmd += "cd %s && runcode.py -w %s %s %s" % \
+         (steering_file_dir, wrkdir, code, steering_filepath)
   cmd += " ; rc=$?"
 
   # Cleanup intermediate files if the computation was successful
index efa22149667481ca36ea5dd2eedfaa82da3e2afd..cf193d324d62782a53433e86f4367b2c51f28ab5 100644 (file)
@@ -125,7 +125,7 @@ class HydroStudyEditor:
         Generating a python script from the eficas info
         """
         # Create "Python script" item
-        from TelApy.api.generate_study import generate_study_script
+        from telapy.api.generate_study import generate_study_script
         with open(filePath) as jdcfile:
             jdc = jdcfile.read()
         params = jdc_to_dict(jdc, ["TELEMAC2D", "_F"])
@@ -147,7 +147,7 @@ class HydroStudyEditor:
         Generating a yacs file from the eficas info
         """
         # Create "Python script" item
-        from TelApy.api.generate_study import generate_study_yacs
+        from telapy.api.generate_study import generate_study_yacs
         with open(filePath) as jdcfile:
             jdc = jdcfile.read()
         params = jdc_to_dict(jdc, ["TELEMAC2D", "_F"])