From: YAUDOUIN Date: Fri, 15 Nov 2019 12:15:43 +0000 (+0100) Subject: Correction for Python3 X-Git-Tag: SH_V2_2_0~27^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0a59d3789858878216aced3a53a0a3fe16e606b9;p=modules%2Fhydrosolver.git Correction for Python3 --- diff --git a/src/salome_hydro/param_study/eficas/param_study_cata.py b/src/salome_hydro/param_study/eficas/param_study_cata.py index ab9e09c..10d56cd 100644 --- a/src/salome_hydro/param_study/eficas/param_study_cata.py +++ b/src/salome_hydro/param_study/eficas/param_study_cata.py @@ -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) diff --git a/src/salome_hydro/run_study/genjob.py b/src/salome_hydro/run_study/genjob.py index 1781aa5..89fdf51 100644 --- a/src/salome_hydro/run_study/genjob.py +++ b/src/salome_hydro/run_study/genjob.py @@ -14,6 +14,9 @@ # # You should have received a copy of the GNU General Public License # along with SALOME HYDRO module. If not, see . +""" +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) diff --git a/src/salome_hydro/run_study/launcher.py b/src/salome_hydro/run_study/launcher.py index b1ee58c..8edb96f 100644 --- a/src/salome_hydro/run_study/launcher.py +++ b/src/salome_hydro/run_study/launcher.py @@ -14,6 +14,9 @@ # # You should have received a copy of the GNU General Public License # along with SALOME HYDRO module. If not, see . +""" +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 diff --git a/src/salome_hydro/study.py b/src/salome_hydro/study.py index efa2214..cf193d3 100644 --- a/src/salome_hydro/study.py +++ b/src/salome_hydro/study.py @@ -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"])