]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
sat #8547 Généralisation de la commande launcher
authorcrouzet <nicolas.crouzet@cea.fr>
Wed, 31 Jul 2019 14:24:18 +0000 (16:24 +0200)
committercrouzet <nicolas.crouzet@cea.fr>
Wed, 31 Jul 2019 14:24:18 +0000 (16:24 +0200)
commands/launcher.py
complete_sat.sh
doc/src/commands/launcher.rst

index dccb9739157d6abfe295074ca0df12297dc5a2bd..aaea98d2e5e5636c90579a00799653928819bb7a 100644 (file)
@@ -29,21 +29,101 @@ import src.debug as DBG
 parser = src.options.Options()
 
 parser.add_option('n', 'name', 'string', 'name', _('Optional: The name of the'
-                            ' launcher (default is '
-                            'APPLICATION.profile.launcher_name)'))
+                  ' launcher (default is APPLICATION.profile.launcher_name)'))
+parser.add_option('e', 'exe', 'string', 'path_exe', _('Use this option to generate a launcher which sets'
+                  ' the environment and call the executable given as argument (its relative path)'))
 parser.add_option('c', 'catalog', 'string', 'catalog',
-    _('Optional: The resources catalog to use'))
+                  _('Optional: The resources catalog to use'))
 parser.add_option('', 'gencat', 'string', 'gencat',
-    _("Optional: Create a resources catalog for the specified machines "
-      "(separated with ',') \n\tNOTICE: this command will ssh to retrieve"
-      " information to each machine in the list"))
+                  _("Optional: Create a resources catalog for the specified machines "
+                  "(separated with ',') \n\tNOTICE: this command will ssh to retrieve"
+                  " information to each machine in the list"))
 parser.add_option('', 'use_mesa', 'boolean', 'use_mesa',
-    _("Optional: Create a launcher that will use mesa products\n\t"
-      "It can be usefull whan salome is used on a remote machine through ssh"))
+                  _("Optional: Create a launcher that will use mesa products\n\t"
+                  "It can be usefull whan salome is used on a remote machine through ssh"))
 parser.add_option('', 'no_path_init', 'boolean', 'no_path_init',
-    _("Optional: Create a launcher that will not reinitilise all path variables\n\t"
-      "By default only PATH is not reinitialised (its value is inherited from user's environment)\n\t"
-      "Use no_path_init option to suppress the reinitilisation of every paths (LD_LIBRARY_PATH, PYTHONPATH, ...)"))
+                 _("Optional: Create a launcher that will not reinitilise all path variables\n\t"
+                   "By default only PATH is not reinitialised (its value is inherited from "
+                   "user's environment)\n\tUse no_path_init option to suppress the reinitilisation"
+                   " of every paths (LD_LIBRARY_PATH, PYTHONPATH, ...)"))
+
+def generate_exe_launch_file(config,
+                             logger,
+                             launcher_name,
+                             pathlauncher,
+                             path_exe,
+                             display=True,
+                             additional_env={},
+                             no_path_init=False):
+    '''Generates the launcher file.
+    
+    :param config Config: The global configuration
+    :param logger Logger: The logger instance to use for the display 
+                          and logging
+    :param launcher_name str: The name of the launcher to generate
+    :param pathlauncher str: The path to the launcher to generate
+    :param path_exe str: The path of the executable to use
+    :param display boolean: If False, do not print anything in the terminal
+    :param additional_env dict: The dict giving additional 
+                                environment variables
+    :return: The launcher file path.
+    :rtype: str
+    '''
+    # build absolute path of exe and check it
+    exepath=os.path.join(config.APPLICATION.workdir, path_exe)
+    if not os.path.exists(exepath):
+        raise src.SatException(_("cannot find executable given : %s" % exepath))
+        
+    # build the launcher path, delete it if it exists
+    filepath = os.path.join(pathlauncher, launcher_name)
+    if os.path.exists(filepath):
+        os.remove(filepath)
+
+    # select the shell for the launcher (bast/bat)
+    # and build the command used to launch the exe
+    if src.architecture.is_windows():
+        shell="bat"
+        cmd="\n\nrem Launch exe with user arguments\n%s " % exepath + "%*"
+    else:
+        shell="bash"
+        cmd="\n\n# Launch exe with user arguments\n%s $*" % exepath
+
+    # the writer to generate the launcher
+    writer = src.environment.FileEnvWriter(config,
+                                           logger,
+                                           pathlauncher,
+                                           src_root=None,
+                                           env_info=None)
+
+    # Display some information
+    if display:
+        logger.write(_("Generating exe launcher for %s :\n") % 
+                     src.printcolors.printcLabel(config.VARS.application), 1)
+        logger.write("  %s\n" % src.printcolors.printcLabel(filepath), 1)
+
+    # Write the environment in the launcher...
+    writer.write_env_file(filepath, 
+                          False,  # for launch
+                          shell,
+                          additional_env=additional_env,
+                          no_path_init=no_path_init)
+
+    # ... and append the launch of the exe
+    with open(filepath, "a") as exe_launcher:
+        exe_launcher.write(cmd)
+
+    # change the rights in order to make the file executable for everybody
+    os.chmod(filepath,
+             stat.S_IRUSR |
+             stat.S_IRGRP |
+             stat.S_IROTH |
+             stat.S_IWUSR |
+             stat.S_IXUSR |
+             stat.S_IXGRP |
+             stat.S_IXOTH)
+
+    return filepath
+
 
 def generate_launch_file(config,
                          logger,
@@ -65,7 +145,6 @@ def generate_launch_file(config,
     :return: The launcher file path.
     :rtype: str
     '''
-    
     # Compute the default launcher path if it is not provided in pathlauncher
     # parameter
     filepath = os.path.join(pathlauncher, launcher_name)
@@ -297,11 +376,20 @@ def run(args, runner, logger):
         src.activate_mesa_property(runner.cfg)
 
     # Generate the launcher
-    launcherPath = generate_launch_file( runner.cfg,
-                                         logger,
-                                         launcher_name,
-                                         launcher_path,
-                                         additional_env = additional_environ,
-                                         no_path_init = no_path_initialisation )
+    if options.path_exe:
+        generate_exe_launch_file(runner.cfg,
+                                 logger,
+                                 launcher_name,
+                                 launcher_path,
+                                 options.path_exe,
+                                 additional_env = additional_environ,
+                                 no_path_init = no_path_initialisation )
+    else:
+        launcherPath = generate_launch_file(runner.cfg,
+                                            logger,
+                                            launcher_name,
+                                            launcher_path,
+                                            additional_env = additional_environ,
+                                            no_path_init = no_path_initialisation )
 
     return 0
index c1f55ca488509e9017dd3dca9a63a7f25afce272..5e68e4259e78d28960ddf2b473e4327e90fe437c 100755 (executable)
@@ -212,7 +212,7 @@ _salomeTools_complete()
             return 0
             ;;
         launcher)
-            opts="--name --catalog --gencat --no_path_init"
+            opts="--name --exe --catalog --gencat --no_path_init"
             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
             return 0
             ;;
index 2041112813db8e830e91a554756f5809c255b433..99e8a032889cd6872dfacfd55d90a796ddb473ef 100644 (file)
@@ -29,6 +29,13 @@ Usage
     
   In this case the launcher do not initialise the path variables (the defaut is to do it only for PATH, not fot LD_LIBRARY_PATH, PYTHONPATH, etc).
 
+* Create a generic launcher, which set the environment (bash or bat) and call the exe given as argument: ::
+
+    sat launcher <application> -e INSTALL/SALOME/bin/salome/salome.py -n salome.sh 
+
+  The launcher will be called salome.sh. It will source the environment and call ``$APPLICATION.workdir``/INSTALL/SALOME/bin/salome/salome.py.
+  The arguments given to salome.sh are transfered to salome.py.  
+
 * Set a specific resources catalog: ::
 
     sat launcher <application>  --catalog  <path of a salome resources catalog>