Salome HOME
decode pip version
[tools/sat.git] / commands / application.py
index f700febbbbcf18cb47877603205b146a6e2179f6..025baf3077a79443c5f4face376680e2bceaeb55 100644 (file)
@@ -25,6 +25,7 @@ import getpass
 
 from src import ElementTree as etree
 import src
+from  src.versionMinorMajorPatch import MinorMajorPatch as MMP
 
 parser = src.options.Options()
 parser.add_option('n', 'name', 'string', 'name',
@@ -85,7 +86,7 @@ def create_config_file(config, modules, env_files, logger):
     for env_file in env_files:
         if env_file.endswith("cfg"):
             f.write('<context path="%s"/>\n' % env_file)
-        else:   
+        else:
             f.write('<prerequisites path="%s"/>\n' % env_file)
 
     f.write('<resources path="CatalogResources.xml"/>\n')
@@ -108,8 +109,8 @@ def create_config_file(config, modules, env_files, logger):
             if src.product.product_is_cpp(mm):
                 # cpp module
                 for aa in src.product.get_product_components(mm):
-                    install_dir = os.path.join(config.APPLICATION.workdir,
-                                               "INSTALL")
+                    install_dir=os.path.join(config.APPLICATION.workdir,
+                                             config.INTERNAL.config.install_dir)
                     mp = os.path.join(install_dir, aa)
                     flagline = add_module_to_appli(f,
                                                    aa,
@@ -193,8 +194,8 @@ def generate_application(config, appli_dir, config_file, logger):
     script = os.path.join(install_KERNEL_dir, "bin", "salome", "appli_gen.py")
     if not os.path.exists(script):
         raise src.SatException(_("KERNEL is not installed"))
-    
-    # Add SALOME python in the environment in order to avoid python version 
+
+    # Add SALOME python in the environment in order to avoid python version
     # problems at appli_gen.py call
     if 'Python' in config.APPLICATION.products:
         envi = src.environment.SalomeEnviron(config,
@@ -202,7 +203,7 @@ def generate_application(config, appli_dir, config_file, logger):
                                                               dict(os.environ)),
                                              True)
         envi.set_a_product('Python', logger)
-    
+
     command = "python %s --prefix=%s --config=%s" % (script,
                                                      appli_dir,
                                                      config_file)
@@ -213,7 +214,7 @@ def generate_application(config, appli_dir, config_file, logger):
                     env=envi.environ.environ,
                     stdout=logger.logTxtFile,
                     stderr=subprocess.STDOUT)
-    
+
     if res != 0:
         raise src.SatException(_("Cannot create application, code = %d\n") % res)
 
@@ -228,9 +229,9 @@ def write_step(logger, message, level=3, pad=50):
 ##
 # Creates a SALOME application.
 def create_application(config, appli_dir, catalog, logger, display=True):
-      
+
     SALOME_modules = get_SALOME_modules(config)
-    
+
     warn = ['KERNEL', 'GUI']
     if display:
         for w in warn:
@@ -244,7 +245,7 @@ def create_application(config, appli_dir, catalog, logger, display=True):
                                    catalog,
                                    logger,
                                    SALOME_modules)
-    
+
     if retcode == 0:
         cmd = src.printcolors.printcLabel("%s/salome" % appli_dir)
 
@@ -259,7 +260,7 @@ def get_SALOME_modules(config):
     l_modules = []
     for product in config.APPLICATION.products:
         product_info = src.product.get_product_config(config, product)
-        if (src.product.product_is_salome(product_info) or 
+        if (src.product.product_is_salome(product_info) or
                src.product.product_is_generated(product_info)):
             l_modules.append(product)
     return l_modules
@@ -272,14 +273,14 @@ def generate_launch_file(config, appli_dir, catalog, logger, l_SALOME_modules):
 
     if len(catalog) > 0 and not os.path.exists(catalog):
         raise IOError(_("Catalog not found: %s") % catalog)
-    
+
     write_step(logger, _("Creating environment files"))
     status = src.KO_STATUS
 
     # build the application (the name depends upon salome version
     env_file = os.path.join(config.APPLICATION.workdir, "env_launch")
     VersionSalome = src.get_salome_version(config)
-    if VersionSalome>=820:
+    if VersionSalome>=MMP([8,2,0]):
         # for salome 8+ we use a salome context file for the virtual app
         app_shell=["cfg", "bash"]
         env_files=[env_file+".cfg", env_file+".sh"]
@@ -290,7 +291,7 @@ def generate_launch_file(config, appli_dir, catalog, logger, l_SALOME_modules):
     try:
         import environ
         # generate only shells the user wants (by default bash, csh, batch)
-        # the environ command will only generate file compatible 
+        # the environ command will only generate file compatible
         # with the current system.
         environ.write_all_source_files(config,
                                        logger,
@@ -339,52 +340,51 @@ def generate_catalog(machines, config, logger):
     user = getpass.getuser()
 
     catfile = src.get_tmp_filename(config, "CatalogResources.xml")
-    catalog = file(catfile, "w")
-    catalog.write("<!DOCTYPE ResourcesCatalog>\n<resources>\n")
-    for k in machines:
-        if not src.architecture.is_windows(): 
-            logger.write("    ssh %s " % (k + " ").ljust(20, '.'), 4)
-            logger.flush()
-
-            ssh_cmd = 'ssh -o "StrictHostKeyChecking no" %s %s' % (k, cmd)
-            p = subprocess.Popen(ssh_cmd, shell=True,
-                    stdin=subprocess.PIPE,
-                    stdout=subprocess.PIPE,
-                    stderr=subprocess.PIPE)
-            p.wait()
-
-            machine_access = (p.returncode == 0) 
-            if not machine_access:
-                logger.write(src.printcolors.printc(src.KO_STATUS) + "\n", 4)
-                logger.write("    " + src.printcolors.printcWarning(p.stderr.read()),
-                             2)
-            else:
-                logger.write(src.printcolors.printc(src.OK_STATUS) + "\n", 4)
-                lines = p.stdout.readlines()
-                freq = lines[0][:-1].split(':')[-1].split('.')[0].strip()
-                nb_proc = len(lines) -1
-                memory = lines[-1].split(':')[-1].split()[0].strip()
-                memory = int(memory) / 1000
-
-            catalog.write("    <machine\n")
-            catalog.write("        protocol=\"ssh\"\n")
-            catalog.write("        nbOfNodes=\"1\"\n")
-            catalog.write("        mode=\"interactif\"\n")
-            catalog.write("        OS=\"LINUX\"\n")
-
-            if (not src.architecture.is_windows()) and machine_access:
-                catalog.write("        CPUFreqMHz=\"%s\"\n" % freq)
-                catalog.write("        nbOfProcPerNode=\"%s\"\n" % nb_proc)
-                catalog.write("        memInMB=\"%s\"\n" % memory)
-
-            catalog.write("        userName=\"%s\"\n" % user)
-            catalog.write("        name=\"%s\"\n" % k)
-            catalog.write("        hostname=\"%s\"\n" % k)
-            catalog.write("    >\n")
-            catalog.write("    </machine>\n")
-
-    catalog.write("</resources>\n")
-    catalog.close()
+    with open(catfile, 'w') as catalog:
+        catalog.write("<!DOCTYPE ResourcesCatalog>\n<resources>\n")
+        for k in machines:
+            if not src.architecture.is_windows():
+                logger.write("    ssh %s " % (k + " ").ljust(20, '.'), 4)
+                logger.flush()
+
+                ssh_cmd = 'ssh -o "StrictHostKeyChecking no" %s %s' % (k, cmd)
+                p = subprocess.Popen(ssh_cmd, shell=True,
+                        stdin=subprocess.PIPE,
+                        stdout=subprocess.PIPE,
+                        stderr=subprocess.PIPE)
+                p.wait()
+
+                machine_access = (p.returncode == 0)
+                if not machine_access:
+                    logger.write(src.printcolors.printc(src.KO_STATUS) + "\n", 4)
+                    logger.write("    " + src.printcolors.printcWarning(p.stderr.read()),
+                                 2)
+                else:
+                    logger.write(src.printcolors.printc(src.OK_STATUS) + "\n", 4)
+                    lines = p.stdout.readlines()
+                    freq = lines[0][:-1].split(':')[-1].split('.')[0].strip()
+                    nb_proc = len(lines) -1
+                    memory = lines[-1].split(':')[-1].split()[0].strip()
+                    memory = int(memory) / 1000
+
+                catalog.write("    <machine\n")
+                catalog.write("        protocol=\"ssh\"\n")
+                catalog.write("        nbOfNodes=\"1\"\n")
+                catalog.write("        mode=\"interactif\"\n")
+                catalog.write("        OS=\"LINUX\"\n")
+
+                if (not src.architecture.is_windows()) and machine_access:
+                    catalog.write("        CPUFreqMHz=\"%s\"\n" % freq)
+                    catalog.write("        nbOfProcPerNode=\"%s\"\n" % nb_proc)
+                    catalog.write("        memInMB=\"%s\"\n" % memory)
+
+                catalog.write("        userName=\"%s\"\n" % user)
+                catalog.write("        name=\"%s\"\n" % k)
+                catalog.write("        hostname=\"%s\"\n" % k)
+                catalog.write("    >\n")
+                catalog.write("    </machine>\n")
+
+        catalog.write("</resources>\n")
     return catfile
 
 ##################################################
@@ -393,7 +393,7 @@ def generate_catalog(machines, config, logger):
 # Describes the command
 def description():
     '''method that is called when salomeTools is called with --help option.
-    
+
     :return: The text to display for the application command description.
     :rtype: str
     '''
@@ -408,7 +408,7 @@ def run(args, runner, logger):
     '''method that is called when salomeTools is called with application
        parameter.
     '''
-    
+
     (options, args) = parser.parse_args(args)
 
     # check for product
@@ -419,7 +419,7 @@ def run(args, runner, logger):
 
     # if section APPLICATION.virtual_app does not exists create one
     if "virtual_app" not in runner.cfg.APPLICATION:
-        msg = _("The section APPLICATION.virtual_app is not defined in the product.")
+        msg = _("The section APPLICATION.virtual_app is not defined in the product. Use sat launcher in state")
         logger.write(src.printcolors.printcError(msg), 1)
         logger.write("\n", 1)
         return 1
@@ -441,7 +441,7 @@ def run(args, runner, logger):
     if options.name:
         runner.cfg.APPLICATION.virtual_app['name'] = options.name
         runner.cfg.APPLICATION.virtual_app['application_name'] = options.name + "_appdir"
-    
+
     application_name = src.get_cfg_param(runner.cfg.APPLICATION.virtual_app,
                                          "application_name",
                                          runner.cfg.APPLICATION.virtual_app.name + "_appdir")
@@ -515,4 +515,3 @@ def run(args, runner, logger):
         logger.write("\n", 3, False)
 
     return retcode
-