From 6bfe1734f7354065cb3cb9640ec523e4cbe43e36 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Jun 2017 13:48:23 +0200 Subject: [PATCH] Adapt SAT to Windows --- commands/launcher.py | 9 ++- commands/package.py | 146 +++++++++++++++++++++++++++++++++++++++---- src/fileEnviron.py | 3 +- src/product.py | 7 ++- src/pyconf.py | 2 +- src/system.py | 2 +- 6 files changed, 147 insertions(+), 22 deletions(-) diff --git a/commands/launcher.py b/commands/launcher.py index 9ce0987..3b33bfb 100644 --- a/commands/launcher.py +++ b/commands/launcher.py @@ -171,7 +171,10 @@ def generate_launch_link(config, # Write the Python environment files env = src.environment.SalomeEnviron( config, - src.fileEnviron.get_file_environ( f, shell, config ) ) + src.fileEnviron.get_file_environ(f, + shell, + config ), + for_package=packageLauncher) env.set_a_product( "Python", logger) # Write the call to the original launcher @@ -332,7 +335,7 @@ def finish_profile_install(config, launcherPath): stat.S_IXOTH) # create a link in root directory to the launcher - if platform.system() != "Windows" : + if platform.system() != "Windows" : link_path = os.path.join(config.APPLICATION.workdir, 'salome') if not os.path.exists(link_path): try: @@ -347,7 +350,7 @@ def finish_profile_install(config, launcherPath): os.symlink(relativeLauncherPath, link_path) except OSError: os.remove(link_path) - os.symlink(relativeLauncherPath, link_path) + os.symlink(relativeLauncherPath, link_path) ################################################## diff --git a/commands/package.py b/commands/package.py index c2d0d47..2ea5bc8 100644 --- a/commands/package.py +++ b/commands/package.py @@ -24,6 +24,7 @@ import tarfile import codecs import string +import launcher import src from application import get_SALOME_modules @@ -39,24 +40,28 @@ PROJECT_DIR = "PROJECT" IGNORED_DIRS = [".git", ".svn"] IGNORED_EXTENSIONS = [] + +sep = os.path.sep +if src.architecture.is_windows(): + sep += os.path.sep PROJECT_TEMPLATE = """#!/usr/bin/env python #-*- coding:utf-8 -*- # The path to the archive root directory -root_path : $PWD + "/../" +root_path : $PWD + \"""" + sep + """..""" + sep + """\" # path to the PROJECT -project_path : $PWD + "/" +project_path : $PWD + \"""" + sep + """\" # Where to search the archives of the products ARCHIVEPATH : $root_path + "ARCHIVES" # Where to search the pyconf of the applications -APPLICATIONPATH : $project_path + "applications/" +APPLICATIONPATH : $project_path + "applications""" + sep + """\" # Where to search the pyconf of the products -PRODUCTPATH : $project_path + "products/" +PRODUCTPATH : $project_path + "products""" + sep + """\" # Where to search the pyconf of the jobs of the project -JOBPATH : $project_path + "jobs/" +JOBPATH : $project_path + "jobs""" + sep + """\" # Where to search the pyconf of the machines of the project -MACHINEPATH : $project_path + "machines/" +MACHINEPATH : $project_path + "machines""" + sep + """\" """ SITE_TEMPLATE = ("""#!/usr/bin/env python @@ -66,7 +71,7 @@ SITE : { log : { - log_dir : $USER.workdir + "/LOGS" + log_dir : $USER.workdir + $VARS.sep + "LOGS" } test :{ tmp_dir_with_application : '/tmp' + $VARS.sep + $VARS.user + """ @@ -392,6 +397,91 @@ def product_appli_creation_script(config, return tmp_file_path + +def generate_launch_link(config, + logger, + launcherPath, + pathlauncher=None, + display=True, + packageLauncher=False): + '''Generates the launcher link that sources Python + and call the actual launcher. + + :param config Config: The global configuration + :param logger Logger: The logger instance to use for the display + and logging + :param launcherPath str: The path to the launcher to call + :param pathlauncher str: The path to the launcher (link) to generate + :param display boolean: If False, do not print anything in the terminal + :param packageLauncher boolean: if True, use a relative path (for package) + :return: The launcher link file path. + :rtype: str + ''' + if pathlauncher is None: + # Make an executable file that sources python, then launch the launcher + # produced by generate_launch_file method + sourceLauncher = os.path.join(config.APPLICATION.workdir, + config.APPLICATION.profile.launcher_name) + else: + sourceLauncher = os.path.join(pathlauncher, + config.APPLICATION.profile.launcher_name) + + # Change the extension for the windows case + if platform.system() == "Windows": + sourceLauncher += '.bat' + + # display some information + if display: + logger.write(_("\nGenerating the executable that sources" + " python and runs the launcher :\n"), 1) + logger.write(" %s\n" % src.printcolors.printcLabel(sourceLauncher), 1) + + # open the file to write + f = open(sourceLauncher, "w") + + # Write the set up of the environment + if platform.system() == "Windows": + shell = 'bat' + else: + shell = 'bash' + + # Write the Python environment files + env = src.environment.SalomeEnviron(config, + src.fileEnviron.get_file_environ(f, shell, config)) + env.set_a_product("Python", logger) + + # Write the call to the original launcher + f.write("\n\n") + if packageLauncher: + cmd = os.path.join('${out_dir_Path}', launcherPath) + else: + cmd = launcherPath + + if platform.system() == "Windows": + cmd = 'python ' + cmd + ' %*' + else: + cmd = cmd + ' $*' + + f.write(cmd) + f.write("\n\n") + + # Write the cleaning of the environment + env.finish(True) + + # Close new launcher + f.close() + os.chmod(sourceLauncher, + stat.S_IRUSR | + stat.S_IRGRP | + stat.S_IROTH | + stat.S_IWUSR | + stat.S_IWGRP | + stat.S_IWOTH | + stat.S_IXUSR | + stat.S_IXGRP | + stat.S_IXOTH) + return sourceLauncher + def binary_package(config, logger, options, tmp_working_dir): '''Prepare a dictionary that stores all the needed directories and files to add in a binary package. @@ -508,10 +598,27 @@ def binary_package(config, logger, options, tmp_working_dir): not(options.without_commercial)) d_products["launcher"] = (launcher_package, launcher_name) + + if src.architecture.is_windows(): + # Add a .bat file that sources python + # and then executes the launcher + link_path = launcher.generate_launch_link(config, + logger, + "salome", + pathlauncher = tmp_working_dir, + display = False, + packageLauncher = binaries_dir_name) + + # Little hack to put out_dir_Path on windows syntax + src.replace_in_file(link_path, 'out_dir_Path\\', '%out_dir_Path%\\') + src.replace_in_file(link_path, '${out_dir_Path}', '%out_dir_Path%') + d_products["Windows launcher"] = (link_path, launcher_name + ".bat") + if options.sources: # if we mix binaries and sources, we add a copy of the launcher, # prefixed with "bin",in order to avoid clashes d_products["launcher (copy)"] = (launcher_package, "bin"+launcher_name) + else: # Provide a script for the creation of an application EDF style appli_script = product_appli_creation_script(config, @@ -1162,8 +1269,11 @@ def run(args, runner, logger): logger.write(src.printcolors.printcError(msg), 1) logger.write("\n", 1) return 1 - - path_targz = os.path.join(dir_name, archive_name + ".tgz") + + extension = ".tgz" + if src.architecture.is_windows(): + extension = ".tar.gz" + path_targz = os.path.join(dir_name, archive_name + extension) src.printcolors.print_value(logger, "Package path", path_targz, 2) @@ -1278,10 +1388,20 @@ def run(args, runner, logger): logger.write(_("OK"), 1) logger.write(_("\n"), 1) return 1 - - # remove the working directory - shutil.rmtree(tmp_working_dir) - + + # remove the working directory + try: + shutil.rmtree(tmp_working_dir) + except Exception as e: + msg1 = _("WARNING: An error occured while removing the working " + "directory") + msg2 = str(e) + msg3 = _("Remove manually the repository %s" % src.printcolors.printcInfo( + tmp_working_dir)) + logger.write("%s\n%s\n%s\n" % (src.printcolors.printcWarning(msg1), + src.printcolors.printcWarning(msg2), + msg3)) + # Print again the path of the package logger.write("\n", 2) src.printcolors.print_value(logger, "Package path", path_targz, 2) diff --git a/src/fileEnviron.py b/src/fileEnviron.py index 27071d0..b8d50e1 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -23,8 +23,7 @@ bat_header="""@echo off rem The following variables are used only in case of a sat package set out_dir_Path=%~dp0 set PRODUCT_OUT_DIR=%out_dir_Path% -set prereq_install_Path=%out_dir_Path%\PREREQUISITES\INSTALL -set prereq_build_Path=%out_dir_Path%\PREREQUISITES\BUILD +set HOME=%userprofile% """ diff --git a/src/product.py b/src/product.py index b1c62eb..7323e62 100644 --- a/src/product.py +++ b/src/product.py @@ -92,7 +92,10 @@ def get_product_config(config, product_name, with_install_dir=True): if prod_info is not None and 'opt_depend' in prod_info: for depend in prod_info.opt_depend: if depend in config.APPLICATION.products: - prod_info.depend.append(depend,'') + try : + prod_info.depend.append(depend,'') + except: # for Win + prod_info.depend.append(depend) # In case of a product get with a vcs, # put the tag (equal to the version) @@ -211,7 +214,7 @@ def get_product_config(config, product_name, with_install_dir=True): raise src.SatException(_("Compilation script not found: %s") % script_name) prod_info.compil_script = script_path - if src.architecture.is_windows(): + if src.architecture.is_windows() and prod_info.compil_script.endswith(".sh"): prod_info.compil_script = prod_info.compil_script[:-len(".sh")] + ".bat" # Check that the script is executable diff --git a/src/pyconf.py b/src/pyconf.py index 713e3fe..80bb499 100644 --- a/src/pyconf.py +++ b/src/pyconf.py @@ -800,7 +800,7 @@ class Sequence(Container): object.__setattr__(self, 'data', []) object.__setattr__(self, 'comments', []) - def append(self, item, comment): + def append(self, item, comment=""): """ Add an item to the sequence. diff --git a/src/system.py b/src/system.py index 78e9946..e38889f 100644 --- a/src/system.py +++ b/src/system.py @@ -45,7 +45,7 @@ def show_in_editor(editor, filePath, logger): cmd = editor % filePath logger.write('Launched command:\n' + cmd + '\n', 5) p = subprocess.Popen(cmd, shell=True) - p.communicate() + #p.communicate() except: logger.write(printcolors.printcError(_("Unable to edit file %s\n") % filePath), 1) -- 2.39.2