1 # Copyright (C) 2012-2013 EDF
3 # This file is part of SALOME HYDRO module.
5 # SALOME HYDRO module is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # SALOME HYDRO module is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with SALOME HYDRO module. If not, see <http://www.gnu.org/licenses/>.
20 from datetime import datetime
25 convertion_script_template = """
26 converter.py %(input_file)s -b %(log_file)s -o %(output_file)s
29 job_script_template = """#!/bin/sh
32 runcode.py %(code)s %(cas)s --ncsize %(nbcore)d
35 def generate_job(pytel_params, resource, telemac_root_dir, telemac_env_file,
36 nbcore, input_data_dir, result_dir):
38 Create a Launcher job using the parameters specified by the user.
41 basename = os.path.basename(pytel_params["FICHIER_CAS"])
42 job_script = job_script_template % {"env_file": telemac_env_file,
43 "code": pytel_params["CODE"],
48 (fd, job_script_file) = tempfile.mkstemp(prefix = "job_" + basename + "_", suffix = ".sh")
50 f = open(job_script_file, "w")
54 # Define job parameters
55 job_params = salome.JobParameters()
56 job_params.job_name = basename
57 job_params.job_type = "command"
58 job_params.job_file = job_script_file
59 input_files = glob.glob(os.path.join(input_data_dir, "*")) + [pytel_params["FICHIER_CAS"]]
60 input_files = list(set(input_files)) # Remove duplicates
61 job_params.in_files = input_files
62 job_params.out_files = []
63 job_params.result_directory = result_dir
65 # Define resource parameters
66 job_params.resource_required = salome.ResourceParameters()
67 job_params.resource_required.name = resource
68 job_params.resource_required.nb_proc = nbcore
70 # Generate name for the working directory
71 res_manager = salome.naming_service.Resolve("/ResourcesManager")
72 res_definition = res_manager.GetResourceDefinition(resource)
73 res_work_dir = res_definition.working_directory
74 if res_work_dir != "":
75 timestr = datetime.now().ctime()
76 timestr = timestr.replace('/', '_')
77 timestr = timestr.replace('-', '_')
78 timestr = timestr.replace(':', '_')
79 timestr = timestr.replace(' ', '_')
80 work_dir = res_work_dir + "/" + job_params.job_name + "_" + timestr
81 job_params.work_directory = work_dir
84 launcher = salome.naming_service.Resolve('/SalomeLauncher')
85 launcher.createJob(job_params)