Salome HOME
Default archive name for products that are in archive mode
[tools/sat.git] / src / product.py
index a165d739c2d08af1889e838492a933ae701b0a2b..d19a5e52629727953782ec51e88fd6688ae57611 100644 (file)
@@ -117,12 +117,29 @@ def get_product_config(config, product_name):
         prod_info.name = product_name
         prod_info.get_source = "native"
     
+    # 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
-    if prod_info is not None:
-        prod_info.debug = debug
-        prod_info.dev = dev
-        prod_info.version = version
-     
+    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)
@@ -134,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):
@@ -155,7 +202,8 @@ 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
 
@@ -182,6 +230,26 @@ def get_product_dependencies(config, product_info):
                 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
     
@@ -284,5 +352,8 @@ def product_has_script(product_info):
     :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