]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
Adapt SAT to Windows
authorunknown <salome@IS228312.intra.cea.fr>
Thu, 1 Jun 2017 11:48:23 +0000 (13:48 +0200)
committerunknown <salome@IS228312.intra.cea.fr>
Thu, 1 Jun 2017 11:48:23 +0000 (13:48 +0200)
commands/launcher.py
commands/package.py
src/fileEnviron.py
src/product.py
src/pyconf.py
src/system.py

index 9ce0987936ba5135d6cf58369b9faa84bbb9853f..3b33bfb6fb87a8e18d8211c8a6662a70ec64b151 100644 (file)
@@ -171,7 +171,10 @@ def generate_launch_link(config,
         \r
     # Write the Python environment files\r
     env = src.environment.SalomeEnviron( config, \r
-                        src.fileEnviron.get_file_environ( f, shell, config ) )\r
+                                         src.fileEnviron.get_file_environ(f,\r
+                                                                          shell,\r
+                                                                          config ),\r
+                                         for_package=packageLauncher)\r
     env.set_a_product( "Python", logger)\r
 \r
     # Write the call to the original launcher\r
@@ -332,7 +335,7 @@ def finish_profile_install(config, launcherPath):
              stat.S_IXOTH)\r
 \r
     # create a link in root directory to the launcher\r
-    if platform.system() != "Windows" :
+    if platform.system() != "Windows" :\r
         link_path = os.path.join(config.APPLICATION.workdir, 'salome')\r
         if not os.path.exists(link_path):\r
             try:\r
@@ -347,7 +350,7 @@ def finish_profile_install(config, launcherPath):
             os.symlink(relativeLauncherPath, link_path)\r
         except OSError:\r
             os.remove(link_path)\r
-            os.symlink(relativeLauncherPath, link_path)
+            os.symlink(relativeLauncherPath, link_path)\r
 \r
 ##################################################\r
 \r
index c2d0d4789397c51db7fbf561d33c087d9dee99b2..2ea5bc82d0caa7d0b49a537de860365390146e31 100644 (file)
@@ -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)
index 27071d0be384cb81a79dc4356d38a78cf30fca78..b8d50e1e4c52a4294d3493591e0b7e2596f58d34 100644 (file)
@@ -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%
 """
 
 
index b1c62ebab71db88dfe3c1dddeb4de2c2a3e7d4bc..7323e62f1b4e0cfae13feaa4ffd62c426e971e4f 100644 (file)
@@ -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
index 713e3fe3e3e1e19d1a499317f5fcf193f8793eb1..80bb4996555f778c0c5b793a3fcf8fa6b8e54909 100644 (file)
@@ -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.
 
index 78e9946b6f50f4ca4c5050e9f3af9ad3731786c0..e38889f679b1bf075d6d13b9c093c8f6c43bbcc1 100644 (file)
@@ -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)