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/>.
18 Script for launch a steering file via the jobmanager
23 from datetime import datetime
28 JOB_SCRIPT_TEMPLATE = """#!/bin/sh
31 runcode.py %(code)s %(cas)s --ncsize %(nbcore)d
35 def generate_job(study_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(study_params["FICHIER_CAS"])
42 job_script = JOB_SCRIPT_TEMPLATE % {"env_file": telemac_env_file,
43 "code": study_params["CODE"],
48 (fd, job_script_file) = \
49 tempfile.mkstemp(prefix="job_" + basename + "_", suffix=".sh")
51 f = open(job_script_file, "w")
55 # Define job parameters
56 job_params = salome.JobParameters()
57 job_params.job_name = basename
58 job_params.job_type = "command"
59 job_params.job_file = job_script_file
60 input_files = glob.glob(os.path.join(input_data_dir, "*")) \
61 + [study_params["FICHIER_CAS"]]
62 input_files = list(set(input_files)) # Remove duplicates
63 job_params.in_files = input_files
64 job_params.out_files = []
65 job_params.result_directory = result_dir
67 # Define resource parameters
68 job_params.resource_required = salome.ResourceParameters()
69 job_params.resource_required.name = resource
70 job_params.resource_required.nb_proc = nbcore
72 # Generate name for the working directory
73 res_manager = salome.naming_service.Resolve("/ResourcesManager")
74 res_definition = res_manager.GetResourceDefinition(resource)
75 res_work_dir = res_definition.working_directory
76 if res_work_dir != "":
77 timestr = datetime.now().ctime()
78 timestr = timestr.replace('/', '_')
79 timestr = timestr.replace('-', '_')
80 timestr = timestr.replace(':', '_')
81 timestr = timestr.replace(' ', '_')
82 work_dir = res_work_dir + "/" + job_params.job_name + "_" + timestr
83 job_params.work_directory = work_dir
86 launcher = salome.naming_service.Resolve('/SalomeLauncher')
87 launcher.createJob(job_params)