Salome HOME
spns #8471 : add Windows case to launch tests with the command 'sat test'
[tools/sat.git] / src / product.py
index b1c62ebab71db88dfe3c1dddeb4de2c2a3e7d4bc..0c6fe4b44665289b2893cf1db4f0eaf5c467de96 100644 (file)
 #  You should have received a copy of the GNU Lesser General Public
 #  License along with this library; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-'''In this file are implemented the methods 
-   relative to the product notion of salomeTools
-'''
+
+"""\
+In this file are implemented the methods 
+relative to the product notion of salomeTools
+"""
 
 import os
 import re
 
 import src
+import src.debug as DBG
 
 AVAILABLE_VCS = ['git', 'svn', 'cvs']
 config_expression = "^config-\d+$"
 VERSION_DELIMITER = "_to_"
 
 def get_product_config(config, product_name, with_install_dir=True):
-    '''Get the specific configuration of a product from the global configuration
+    """Get the specific configuration of a product from the global configuration
     
     :param config Config: The global configuration
     :param product_name str: The name of the product
@@ -38,7 +41,7 @@ def get_product_config(config, product_name, with_install_dir=True):
                                      of the function check_config_exists)
     :return: the specific configuration of the product
     :rtype: Config
-    '''
+    """
     
     # Get the version of the product from the application definition
     version = config.APPLICATION.products[product_name]
@@ -51,6 +54,7 @@ def get_product_config(config, product_name, with_install_dir=True):
     # current product 
     debug = 'no'
     dev = 'no'
+    verbose = 'no'
     base = 'maybe'
     section = None
     if isinstance(version, src.pyconf.Mapping):
@@ -65,6 +69,10 @@ def get_product_config(config, product_name, with_install_dir=True):
         if 'debug' in dic_version:
             debug = dic_version.debug
         
+        # Get the verbose if any
+        if 'verbose' in dic_version:
+            verbose = dic_version.verbose
+        
         # Get the dev if any
         if 'dev' in dic_version:
             dev = dic_version.dev
@@ -145,17 +153,23 @@ def get_product_config(config, product_name, with_install_dir=True):
         prod_pyconf_path = src.find_file_in_lpath(product_name + ".pyconf",
                                                   config.PATHS.PRODUCTPATH)
         if not prod_pyconf_path:
-            msg = _("No definition found for the product %s\n"
-               "Please create a %s.pyconf file." % (product_name, product_name))
+            msg = _("""\
+No definition found for the product %(1)s.
+Please create a %(2)s.pyconf file somewhere in:
+%(3)s""") % {
+  "1": product_name, 
+  "2": product_name,
+  "3": config.PATHS.PRODUCTPATH }
         else:
-            msg = _("No definition corresponding to the version %(version)s was"
-                    " found in the file %(prod_file_path)s.\nPlease add a "
-                    "section in it." % {"version" : vv,
-                                        "prod_file_path" : prod_pyconf_path} )
+            msg = _("""\
+No definition corresponding to the version %(1)s was found in the file:
+  %(2)s.
+Please add a section in it.""") % {"1" : vv, "2" : prod_pyconf_path}
         raise src.SatException(msg)
     
     # Set the debug, dev and version keys
     prod_info.debug = debug
+    prod_info.verbose = verbose
     prod_info.dev = dev
     prod_info.version = version
     
@@ -170,11 +184,13 @@ def get_product_config(config, product_name, with_install_dir=True):
             arch_path = src.find_file_in_lpath(arch_name,
                                                config.PATHS.ARCHIVEPATH)
             if not arch_path:
-                msg = _("Archive %(arch_name)s for %(prod_name)s not found:"
-                            "\n" % {"arch_name" : arch_name,
-                                     "prod_name" : prod_info.name}) 
-                raise src.SatException(msg)
-            prod_info.archive_info.archive_name = arch_path
+                msg = _("Archive %(1)s for %(2)s not found in config.PATHS.ARCHIVEPATH") % \
+                       {"1" : arch_name, "2" : prod_info.name}
+                DBG.tofix(msg, config.PATHS.ARCHIVEPATH)
+                prod_info.archive_info.archive_name = arch_name #without path
+                # raise src.SatException(msg) #may be a warning, continue #8646
+            else:
+                prod_info.archive_info.archive_name = arch_path
         else:
             if (os.path.basename(prod_info.archive_info.archive_name) == 
                                         prod_info.archive_info.archive_name):
@@ -183,60 +199,68 @@ def get_product_config(config, product_name, with_install_dir=True):
                                             arch_name,
                                             config.PATHS.ARCHIVEPATH)
                 if not arch_path:
-                    msg = _("Archive %(arch_name)s for %(prod_name)s not found:"
-                                "\n" % {"arch_name" : arch_name,
-                                         "prod_name" : prod_info.name}) 
-                    raise src.SatException(msg)
-                prod_info.archive_info.archive_name = arch_path
+                    msg = _("Archive %(1)s for %(2)s not found in config.PATHS.ARCHIVEPATH") % \
+                           {"1" : arch_name, "2" : prod_info.name}
+                    DBG.tofix(msg, config.PATHS.ARCHIVEPATH) #avoid 2 messages in compile
+                    prod_info.archive_info.archive_name = arch_name #without path
+                    # raise src.SatException(msg) #may be a warning, continue #8646
+                else:
+                    prod_info.archive_info.archive_name = arch_path
+
         
     # If the product compiles with a script, check the script existence
     # and if it is executable
     if product_has_script(prod_info):
         # Check the compil_script key existence
         if "compil_script" not in prod_info:
-            msg = _("No compilation script found for the product %s\n"
-                "Please provide a \"compil_script\" key in its definition." 
-                % (product_name))
+            msg = _("""\
+No compilation script found for the product %s.
+Please provide a 'compil_script' key in its definition.""") % product_name
             raise src.SatException(msg)
         
-        # Get the path of the script
+        # Get the path of the script file
+        # if windows supposed '.bat', if linux supposed '.sh'
+        # but user set extension script file in his pyconf as he wants, no obligation.
         script = prod_info.compil_script
         script_name = os.path.basename(script)
         if script == script_name:
             # Only a name is given. Search in the default directory
-            script_path = src.find_file_in_lpath(script_name,
-                                                 config.PATHS.PRODUCTPATH,
-                                                 "compil_scripts")
+            script_path = src.find_file_in_lpath(script_name, config.PATHS.PRODUCTPATH, "compil_scripts")
             if not script_path:
-                raise src.SatException(_("Compilation script not found: %s") % 
-                                   script_name)
+                msg = _("Compilation script not found: %s") % script_name
+                DBG.tofix(msg, config.PATHS.PRODUCTPATH, True) # say where searched
+                raise src.SatException(msg)
             prod_info.compil_script = script_path
-            if src.architecture.is_windows():
-                prod_info.compil_script = prod_info.compil_script[:-len(".sh")] + ".bat"
+
        
         # Check that the script is executable
         if not os.access(prod_info.compil_script, os.X_OK):
-            raise src.SatException(
-                    _("Compilation script cannot be executed: %s") % 
-                    prod_info.compil_script)
+            #raise src.SatException(
+            #        _("Compilation script cannot be executed: %s") % 
+            #        prod_info.compil_script)
+            # just as warning, problem later...
+            DBG.tofix("Compilation script is not execute mode file", prod_info.compil_script, True)
     
     # Get the full paths of all the patches
     if product_has_patches(prod_info):
         patches = []
-        for patch in prod_info.patches:
-            patch_path = patch
-            # If only a filename, then search for the patch in the PRODUCTPATH
-            if os.path.basename(patch_path) == patch_path:
-                # Search in the PRODUCTPATH/patches
-                patch_path = src.find_file_in_lpath(patch,
-                                                    config.PATHS.PRODUCTPATH,
-                                                    "patches")
-                if not patch_path:
-                    msg = _("Patch %(patch_name)s for %(prod_name)s not found:"
-                            "\n" % {"patch_name" : patch,
-                                     "prod_name" : prod_info.name}) 
-                    raise src.SatException(msg)
-            patches.append(patch_path)
+        try:
+          for patch in prod_info.patches:
+              patch_path = patch
+              # If only a filename, then search for the patch in the PRODUCTPATH
+              if os.path.basename(patch_path) == patch_path:
+                  # Search in the PRODUCTPATH/patches
+                  patch_path = src.find_file_in_lpath(patch,
+                                                      config.PATHS.PRODUCTPATH,
+                                                      "patches")
+                  if not patch_path:
+                      msg = _("Patch %(patch_name)s for %(prod_name)s not found:"
+                              "\n" % {"patch_name" : patch,
+                                       "prod_name" : prod_info.name}) 
+                      raise src.SatException(msg)
+              patches.append(patch_path)
+        except:
+          DBG.tofix("problem in prod_info.patches", prod_info)
         prod_info.patches = patches
 
     # Get the full paths of the environment scripts
@@ -277,7 +301,7 @@ def get_product_config(config, product_name, with_install_dir=True):
     return prod_info
 
 def get_product_section(config, product_name, version, section=None):
-    '''Get the product description from the configuration
+    """Get the product description from the configuration
     
     :param config Config: The global configuration
     :param product_name str: The product name
@@ -286,7 +310,7 @@ def get_product_section(config, product_name, version, section=None):
                         explicitly given
     :return: The product description
     :rtype: Config
-    '''
+    """
 
     # if section is not None, try to get the corresponding section
     if section:
@@ -332,20 +356,20 @@ def get_product_section(config, product_name, version, section=None):
     return None
     
 def get_install_dir(config, base, version, prod_info):
-    '''Compute the installation directory of a given product 
+    """Compute the installation directory of a given product 
     
     :param config Config: The global configuration
     :param base str: This corresponds to the value given by user in its 
                      application.pyconf for the specific product. If "yes", the
-                    user wants the product to be in base. If "no", he wants the
-                    product to be in the application workdir
+                     user wants the product to be in base. If "no", he wants the
+                     product to be in the application workdir
     :param version str: The version of the product
     :param product_info Config: The configuration specific to 
                                the product
     
     :return: The path of the product installation
     :rtype: str
-    '''
+    """
     install_dir = ""
     in_base = False
     if (("install_dir" in prod_info and prod_info.install_dir == "base") 
@@ -369,7 +393,7 @@ def get_install_dir(config, base, version, prod_info):
     return install_dir
 
 def get_base_install_dir(config, prod_info, version):
-    '''Compute the installation directory of a product in base 
+    """Compute the installation directory of a product in base 
     
     :param config Config: The global configuration
     :param product_info Config: The configuration specific to 
@@ -377,7 +401,7 @@ def get_base_install_dir(config, prod_info, version):
     :param version str: The version of the product    
     :return: The path of the product installation
     :rtype: str
-    '''    
+    """    
     base_path = src.get_base_path(config) 
     prod_dir = os.path.join(base_path, prod_info.name + "-" + version)
     if not os.path.exists(prod_dir):
@@ -401,9 +425,10 @@ def get_base_install_dir(config, prod_info, version):
     return install_dir
 
 def check_config_exists(config, prod_dir, prod_info):
-    '''Verify that the installation directory of a product in a base exists
-       Check all the config-<i> directory and verify the sat-config.pyconf file
-       that is in it 
+    """\
+    Verify that the installation directory of a product in a base exists
+    Check all the config-<i> directory and verify the sat-config.pyconf file
+    that is in it 
     
     :param config Config: The global configuration
     :param prod_dir str: The product installation directory path 
@@ -413,7 +438,7 @@ def check_config_exists(config, prod_dir, prod_info):
     :return: True or false is the installation is found or not 
              and if it is found, the path of the found installation
     :rtype: (boolean, str)
-    '''   
+    """   
     # check if the directories or files of the directory corresponds to the 
     # directory installation of the product
     l_dir_and_files = os.listdir(prod_dir)
@@ -466,14 +491,14 @@ def check_config_exists(config, prod_dir, prod_info):
             
     
 def get_products_infos(lproducts, config):
-    '''Get the specific configuration of a list of products
+    """Get the specific configuration of a list of products
     
     :param lproducts List: The list of product names
     :param config Config: The global configuration
     :return: the list of tuples 
              (product name, specific configuration of the product)
     :rtype: [(str, Config)]
-    '''
+    """
     products_infos = []
     # Loop on product names
     for prod in lproducts:       
@@ -488,15 +513,16 @@ def get_products_infos(lproducts, config):
     return products_infos
 
 def get_product_dependencies(config, product_info):
-    '''Get recursively the list of products that are 
-       in the product_info dependencies
+    """\
+    Get recursively the list of products that are 
+    in the product_info dependencies
     
     :param config Config: The global configuration
     :param product_info Config: The configuration specific to 
                                the product
     :return: the list of products in dependence
     :rtype: list
-    '''
+    """
     if "depend" not in product_info or product_info.depend == []:
         return []
     res = []
@@ -513,14 +539,15 @@ def get_product_dependencies(config, product_info):
     return res
 
 def check_installation(product_info):
-    '''Verify if a product is well installed. Checks install directory presence
-       and some additional files if it is defined in the config 
+    """\
+    Verify if a product is well installed. Checks install directory presence
+    and some additional files if it is defined in the config 
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if it is well installed
     :rtype: boolean
-    '''
+    """
     if not product_compiles(product_info):
         return True
     install_dir = product_info.install_dir
@@ -534,167 +561,174 @@ def check_installation(product_info):
                 return False
     return True
 
-def product_is_sample(product_info):
-    '''Know if a product has the sample type
+def check_source(product_info):
+    """Verify if a sources of product is preset. Checks source directory presence
     
     :param product_info Config: The configuration specific to 
                                the product
-    :return: True if the product has the sample type, else False
+    :return: True if it is well installed
     :rtype: boolean
-    '''
-    if 'type' in product_info:
-        ptype = product_info.type
-        return ptype.lower() == 'sample'
-    else:
+    """
+    DBG.write("check_source product_info", product_info)
+    source_dir = product_info.source_dir
+    if not os.path.exists(source_dir):
         return False
+    if ("present_files" in product_info and 
+        "source" in product_info.present_files):
+        for file_relative_path in product_info.present_files.source:
+            file_path = os.path.join(source_dir, file_relative_path)
+            if not os.path.exists(file_path):
+                return False
+    return True
 
 def product_is_salome(product_info):
-    '''Know if a product is of type salome
+    """Know if a product is a SALOME module
     
     :param product_info Config: The configuration specific to 
                                the product
-    :return: True if the product is salome, else False
+    :return: True if the product is a SALOME module, else False
     :rtype: boolean
-    '''
-    if 'type' in product_info:
-        ptype = product_info.type
-        return ptype.lower() == 'salome'
-    else:
-        return False
+    """
+    return ("properties" in product_info and
+            "is_SALOME_module" in product_info.properties and
+            product_info.properties.is_SALOME_module == "yes")
 
 def product_is_fixed(product_info):
-    '''Know if a product is fixed
+    """Know if a product is fixed
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is fixed, else False
     :rtype: boolean
-    '''
+    """
     get_src = product_info.get_source
     return get_src.lower() == 'fixed'
 
 def product_is_native(product_info):
-    '''Know if a product is native
+    """Know if a product is native
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is native, else False
     :rtype: boolean
-    '''
+    """
     get_src = product_info.get_source
     return get_src.lower() == 'native'
 
 def product_is_dev(product_info):
-    '''Know if a product is in dev mode
+    """Know if a product is in dev mode
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is in dev mode, else False
     :rtype: boolean
-    '''
+    """
     dev = product_info.dev
-    return dev.lower() == 'yes'
+    res = (dev.lower() == 'yes')
+    DBG.write('product_is_dev %s' % product_info.name, res)
+    # if product_info.name == "XDATA": return True #test #10569
+    return res
 
 def product_is_debug(product_info):
-    '''Know if a product is in debug mode
+    """Know if a product is in debug mode
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is in debug mode, else False
     :rtype: boolean
-    '''
+    """
     debug = product_info.debug
     return debug.lower() == 'yes'
 
+def product_is_verbose(product_info):
+    """Know if a product is in verbose mode
+    
+    :param product_info Config: The configuration specific to 
+                               the product
+    :return: True if the product is in verbose mode, else False
+    :rtype: boolean
+    """
+    verbose = product_info.verbose
+    return verbose.lower() == 'yes'
+
 def product_is_autotools(product_info):
-    '''Know if a product is compiled using the autotools
+    """Know if a product is compiled using the autotools
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is autotools, else False
     :rtype: boolean
-    '''
+    """
     build_src = product_info.build_source
     return build_src.lower() == 'autotools'
 
 def product_is_cmake(product_info):
-    '''Know if a product is compiled using the cmake
+    """Know if a product is compiled using the cmake
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is cmake, else False
     :rtype: boolean
-    '''
+    """
     build_src = product_info.build_source
     return build_src.lower() == 'cmake'
 
 def product_is_vcs(product_info):
-    '''Know if a product is download using git, svn or cvs (not archive)
+    """Know if a product is download using git, svn or cvs (not archive)
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is vcs, else False
     :rtype: boolean
-    '''
+    """
     return product_info.get_source in AVAILABLE_VCS
 
-def product_is_SALOME(product_info):
-    '''Know if a product is a SALOME module
-    
-    :param product_info Config: The configuration specific to 
-                               the product
-    :return: True if the product is a SALOME module, else False
-    :rtype: boolean
-    '''
-    return ("properties" in product_info and
-            "is_SALOME_module" in product_info.properties and
-            product_info.properties.is_SALOME_module == "yes")
-
 def product_is_smesh_plugin(product_info):
-    '''Know if a product is a SMESH plugin
+    """Know if a product is a SMESH plugin
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is a SMESH plugin, else False
     :rtype: boolean
-    '''
+    """
     return ("properties" in product_info and
             "smesh_plugin" in product_info.properties and
             product_info.properties.smesh_plugin == "yes")
 
 def product_is_cpp(product_info):
-    '''Know if a product is cpp
+    """Know if a product is cpp
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is a cpp, else False
     :rtype: boolean
-    '''
+    """
     return ("properties" in product_info and
             "cpp" in product_info.properties and
             product_info.properties.cpp == "yes")
 
 def product_compiles(product_info):
-    '''Know if a product compiles or not (some products do not have a 
-       compilation procedure)
+    """\
+    Know if a product compiles or not 
+    (some products do not have a compilation procedure)
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product compiles, else False
     :rtype: boolean
-    '''
+    """
     return not("properties" in product_info and
             "compilation" in product_info.properties and
             product_info.properties.compilation == "no")
 
 def product_has_script(product_info):
-    '''Know if a product has a compilation script
+    """Know if a product has a compilation script
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product it has a compilation script, else False
     :rtype: boolean
-    '''
+    """
     if "build_source" not in product_info:
         # Native case
         return False
@@ -702,33 +736,36 @@ def product_has_script(product_info):
     return build_src.lower() == 'script'
 
 def product_has_env_script(product_info):
-    '''Know if a product has an environment script
+    """Know if a product has an environment script
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product it has an environment script, else False
     :rtype: boolean
-    '''
+    """
     return "environ" in product_info and "env_script" in product_info.environ
 
 def product_has_patches(product_info):
-    '''Know if a product has one or more patches
+    """Know if a product has one or more patches
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product has one or more patches
     :rtype: boolean
-    '''
-    return "patches" in product_info and len(product_info.patches) > 0
+    """   
+    res = ( "patches" in product_info and len(product_info.patches) > 0 )
+    DBG.write('product_has_patches %s' % product_info.name, res)
+    # if product_info.name == "XDATA": return True #test #10569
+    return res
 
 def product_has_logo(product_info):
-    '''Know if a product has a logo (YACSGEN generate)
+    """Know if a product has a logo (YACSGEN generate)
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: The path of the logo if the product has a logo, else False
     :rtype: Str
-    '''
+    """
     if ("properties" in product_info and
             "logo" in product_info.properties):
         return product_info.properties.logo
@@ -736,48 +773,48 @@ def product_has_logo(product_info):
         return False
 
 def product_has_salome_gui(product_info):
-    '''Know if a product has a SALOME gui
+    """Know if a product has a SALOME gui
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product has a SALOME gui, else False
     :rtype: Boolean
-    '''
+    """
     return ("properties" in product_info and
             "has_salome_gui" in product_info.properties and
             product_info.properties.has_salome_gui == "yes")
 
 def product_is_mpi(product_info):
-    '''Know if a product has openmpi in its dependencies
+    """Know if a product has openmpi in its dependencies
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product has openmpi inits dependencies
     :rtype: boolean
-    '''
+    """
     return "openmpi" in product_info.depend
 
 def product_is_generated(product_info):
-    '''Know if a product is generated (YACSGEN)
+    """Know if a product is generated (YACSGEN)
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: True if the product is generated
     :rtype: boolean
-    '''
+    """
     return ("properties" in product_info and
             "generate" in product_info.properties and
             product_info.properties.generate == "yes")
 
 def get_product_components(product_info):
-    '''Get the component list to generate with the product
+    """Get the component list to generate with the product
     
     :param product_info Config: The configuration specific to 
                                the product
     :return: The list of names of the components
     :rtype: List
     
-    '''
+    """
     if not product_is_generated(product_info):
         return []