2 # -*- coding: utf-8 -*-
3 ## Copyright (C) 2021-2024 CEA/DEN, EDF R&D, OPEN CASCADE
5 ## This library is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU Lesser General Public
7 ## License as published by the Free Software Foundation; either
8 ## version 2.1 of the License, or (at your option) any later version.
10 ## This library 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 GNU
13 ## Lesser General Public License for more details.
15 ## You should have received a copy of the GNU Lesser General Public
16 ## License along with this library; if not, write to the Free Software
17 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ## See http://www.salome-platform.org/ or email :
20 ## webmaster.salome@opencascade.com
23 File to send files on remote ressource
25 from os import environ, path
27 from argparse import ArgumentParser
31 def create_launcher():
32 """ Initialise pylauncher
34 launcher = pylauncher.Launcher_cpp()
35 launcher.SetResourcesManager(create_resources_manager())
38 def create_resources_manager():
39 """ Look for the catalog file and create a ressource manager with it """
40 # localhost is defined anyway, even if the catalog file does not exist.
41 catalog_path = environ.get("USER_CATALOG_RESOURCES_FILE", "")
42 if not path.isfile(catalog_path):
43 salome_path = environ.get("ROOT_SALOME_INSTALL", "")
44 catalog_path = path.join(salome_path, "CatalogResources.xml")
45 if not path.isfile(catalog_path):
48 return pylauncher.ResourcesManager_cpp(catalog_path)
50 def create_job_parameters():
51 """ Initialsie JobParameters """
52 jparam = pylauncher.JobParameters_cpp()
53 jparam.resource_required = create_resource_parameters()
56 def create_resource_parameters():
57 """ Init resourceParams """
58 return pylauncher.resourceParams()
61 """ job to send a file to the cluster """
63 launcher = create_launcher()
65 # See SALOME_Launcher documentation for parameters
66 job_params = create_job_parameters()
67 job_params.job_type = "command_salome" # creates CatalogResources.xml
69 local_dir = path.dirname(args.input_file)
71 # job_params.pre_command = pre_command # command to run on frontal
72 # script to run in batch mode
73 run_script = path.join(path.dirname(args.input_file), "run.sh")
74 with open(run_script, "w") as f:
75 f.write("#!/bin/bash\n")
76 job_params.job_file = run_script
77 job_params.resource_required.nb_proc = 1
79 # files to copy to remote working dir
80 # Directories are copied recursively.
81 # job_file script is automaticaly copied.
82 job_params.in_files = [args.input_file]
83 print("in_files", job_params.in_files)
84 # local path where to copy out_files
85 job_params.result_directory = local_dir
87 job_params.job_name = "SMESH_transfer"
88 job_params.resource_required.name = args.resource
90 # remote job directory
91 # Retrieve working dir from catalog
92 res_manager = create_resources_manager()
93 res_params = res_manager.GetResourceDefinition(args.resource)
94 job_params.work_directory = path.join(\
95 res_params.working_directory,
96 path.basename(path.dirname(args.input_file)))
98 print("work_directory", job_params.work_directory)
100 job_id = launcher.createJob(job_params) #SALOME id of the job
101 launcher.exportInputFiles(job_id)
105 """ Define and parse arguments for the script """
106 parser = ArgumentParser()
107 parser.add_argument("input_file",\
112 parser.add_argument("--resource",
113 help="resource from SALOME Catalog")
115 args = parser.parse_args()
120 """ Main function """
124 if __name__ == "__main__":