Salome HOME
Default archive name for products that are in archive mode
[tools/sat.git] / src / product.py
index de0e1d3a4f59c7276337bca4fae7a9ca2d68b49c..d19a5e52629727953782ec51e88fd6688ae57611 100644 (file)
@@ -117,11 +117,29 @@ def get_product_config(config, product_name):
         prod_info.name = product_name
         prod_info.get_source = "native"
     
-    # Set the debug and dev keys
-    if prod_info is not None:
-        prod_info.debug = debug
-        prod_info.dev = dev
-     
+    # If prod_info is still None, it means that there is no product definition
+    # in the config. The user has to provide it.
+    if prod_info is None:
+        msg = _("No definition found for the product %s\n"
+            "Please create a %s.pyconf file." % (product_name, product_name))
+        raise src.SatException(msg)
+    
+    # Set the debug, dev and version keys
+    prod_info.debug = debug
+    prod_info.dev = dev
+    prod_info.version = version
+    
+    # Set the archive_info if the product is get in archive mode
+    if prod_info.get_source == "archive":
+        if not "archive_info" in prod_info:
+            prod_info.addMapping("archive_info",
+                                 src.pyconf.Mapping(prod_info),
+                                 "")
+        if "archive_name" not in prod_info.archive_info:
+            arch_name = os.path.join(config.SITE.prepare.archive_dir,
+                                     product_name + "-" + version + ".tar.gz")
+            prod_info.archive_info.archive_name = arch_name
+    
     # Set the install_dir key
     if "install_dir" not in prod_info:
         # Set it to the default value (in application directory)
@@ -133,8 +151,38 @@ def get_product_config(config, product_name):
             # Get the product base of the application
             base_path = src.get_base_path(config) 
             prod_info.install_dir = os.path.join(base_path,
-                                            prod_info.name)
-       
+                                            prod_info.name + "-" + version)
+    
+    # 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))
+            raise src.SatException(msg)
+        
+        # Get the path of the script
+        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 = os.path.join(
+                    config.INTERNAL.compile.default_script_dir, script_name)
+            prod_info.compil_script = script_path
+
+        # Check script existence
+        if not os.path.exists(prod_info.compil_script):
+            raise src.SatException(_("Compilation script not found: %s") % 
+                                   prod_info.compil_script)
+        
+        # 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)
+        
     return prod_info
 
 def get_products_infos(lproducts, config):
@@ -154,10 +202,53 @@ def get_products_infos(lproducts, config):
         if prod_info is not None:
             products_infos.append((prod, prod_info))
         else:
-            msg = _("The %s product has no definition in the configuration.") % prod
+            msg = _("The %s product has no definition "
+                    "in the configuration.") % prod
             raise src.SatException(msg)
     return products_infos
 
+def get_product_dependencies(config, product_info):
+    '''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 = []
+    for prod in product_info.depend:
+        if prod not in res:
+            res.append(prod)
+        prod_info = get_product_config(config, prod)
+        dep_prod = get_product_dependencies(config, prod_info)
+        for prod_in_dep in dep_prod:
+            if prod_in_dep not in res:
+                res.append(prod_in_dep)
+    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 
+    
+    :param product_info Config: The configuration specific to 
+                               the product
+    :return: True if it is well installed
+    :rtype: boolean
+    '''
+    install_dir = product_info.install_dir
+    if not os.path.exists(install_dir):
+        return False
+    if ("present_files" in product_info and 
+        "install" in product_info.present_files):
+        for file_relative_path in product_info.present_files.install:
+            file_path = os.path.join(install_dir, file_relative_path)
+            if not os.path.exists(file_path):
+                return False
+    return True
 
 def product_is_sample(product_info):
     '''Know if a product has the sample type
@@ -173,6 +264,20 @@ def product_is_sample(product_info):
     else:
         return False
 
+def product_is_salome(product_info):
+    '''Know if a product is of type salome
+    
+    :param product_info Config: The configuration specific to 
+                               the product
+    :return: True if the product is salome, else False
+    :rtype: boolean
+    '''
+    if 'type' in product_info:
+        ptype = product_info.type
+        return ptype.lower() == 'salome'
+    else:
+        return False
+
 def product_is_fixed(product_info):
     '''Know if a product is fixed
     
@@ -215,4 +320,40 @@ def product_is_debug(product_info):
     :rtype: boolean
     '''
     debug = product_info.debug
-    return debug.lower() == 'yes'
\ No newline at end of file
+    return debug.lower() == 'yes'
+
+def product_is_autotools(product_info):
+    '''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
+    
+    :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_has_script(product_info):
+    '''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
+    build_src = product_info.build_source
+    return build_src.lower() == 'script'
\ No newline at end of file