+ _("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
+