Salome HOME
sat #32672 : nouvelle clé post_script pour exécuter un script post installation
authorcrouzet <nicolas.crouzet@cea.fr>
Tue, 15 Nov 2022 08:43:42 +0000 (09:43 +0100)
committercrouzet <nicolas.crouzet@cea.fr>
Tue, 15 Nov 2022 08:43:42 +0000 (09:43 +0100)
commands/makeinstall.py
commands/script.py
doc/src/configuration.rst
src/product.py

index b01ee62679f8468bc138c787e672e71ba38a6ecb..eea3f85b7615712108646a33b69652c3e7777c53 100644 (file)
@@ -112,14 +112,28 @@ def makeinstall_product(p_name_info, config, logger):
         logger.write("\r" + header + src.printcolors.printcError("KO"))
         logger.write("==== %(KO)s in make install of %(name)s \n" %
             { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
+        logger.write("\n", 3, False)
         logger.flush()
-    else:
-        logger.write("\r%s%s" % (header, " " * 20), 3)
-        logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
-        logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
-        logger.write("==== Make install of %(name)s %(OK)s \n" %
-            { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
-        logger.flush()
+        return res
+
+    if src.product.product_has_post_script(p_info):
+        # the product has a post install script we run
+        res = builder.do_script_build(p_info.post_script)
+        if res > 0:
+            logger.write("\r%s%s" % (header, " " * len_end_line), 3)
+            logger.write("\r" + header + src.printcolors.printcError("KO"))
+            logger.write("==== %(KO)s in post script execution of %(name)s \n" %
+                { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
+            logger.write("\n", 3, False)
+            logger.flush()
+            return res
+
+    logger.write("\r%s%s" % (header, " " * 20), 3)
+    logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
+    logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
+    logger.write("==== Make install of %(name)s %(OK)s \n" %
+        { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
+    logger.flush()
     logger.write("\n", 3, False)
 
     return res
index 0ca14348b6cdba3ee9c0f77e6f551a2a43ca9b19..824a1331b20fc139ee661b600cf6fb15edbf6523 100644 (file)
@@ -127,15 +127,32 @@ def run_script_of_product(p_name_info, nb_proc, config, logger):
         logger.write("\r" + header + src.printcolors.printcError("KO"))
         logger.write("==== %(KO)s in script execution of %(name)s \n" %
             { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
+        logger.write("\n", 3, False)
         logger.flush()
-    else:
-        logger.write("\r%s%s" % (header, " " * len_end_line), 3)
-        logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
-        logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
-        logger.write("==== Script execution of %(name)s %(OK)s \n" %
-            { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
-        logger.flush()
+        return res
+
+    if src.product.product_has_post_script(p_info):
+        # the product has a post install script we run
+        #script_path_display = src.printcolors.printcLabel(p_info.p_info.post_script)
+        #log_step(logger, header, "POST SCRIPT " + script_path_display)
+        res = builder.do_script_build(p_info.post_script)
+        #log_res_step(logger, res)
+        if res > 0:
+            logger.write("\r%s%s" % (header, " " * len_end_line), 3)
+            logger.write("\r" + header + src.printcolors.printcError("KO"))
+            logger.write("==== %(KO)s in post script execution of %(name)s \n" %
+                { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
+            logger.write("\n", 3, False)
+            logger.flush()
+            return res
+    
+    logger.write("\r%s%s" % (header, " " * len_end_line), 3)
+    logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
+    logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
+    logger.write("==== Script execution of %(name)s %(OK)s \n" %
+        { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
     logger.write("\n", 3, False)
+    logger.flush()
 
     return res
 
index 2877a85fd69db669b3c2db3e946b7e3f7650fdc3..c9f7381bcfdb9117505e04f1098c59a45d2fed21 100644 (file)
@@ -259,6 +259,7 @@ Available product configuration flags
 * **name** : the name of the product 
 * **build_source** : the method to use when getting the sources, possible choices are script/cmake/autotools. If "script" is chosen, a compilation script should be provided with compil_script key
 * **compil_script** : to specify a compilation script (in conjunction with build_source set to "script"). The programming language is bash under linux, and bat under windows.  
+* **post_script** : to specify a post installation script (use it as a hook to do extra wokr after installation).
 * **get_source** : the mode to get the sources, possible choices are archive/git/svn/cvs
 * **depend** : to give SAT the dependencies of the product
 * **patches** : provides a list of patches, if required
index 3b385b1e6578f45a2d3056de3bb7a13d71d1578e..ffc75c909ccc0b89ce2deca8a8a276af7a620ddc 100644 (file)
@@ -313,6 +313,30 @@ Please provide a 'compil_script' key in its definition.""") % product_name
         if os.path.exists(prod_info.compil_script) and not os.access(prod_info.compil_script, os.X_OK):
             DBG.tofix("Compilation script  file is not in 'execute mode'", prod_info.compil_script, True)
     
+    # If the product has a post install script, check the script existence
+    # and if it is executable
+    if product_has_post_script(prod_info):
+        # Check the compil_script key existence
+        
+        # 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.post_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, "post_scripts")
+            if not script_path:
+                msg = _("Post install script %s not found in") % script_name
+                DBG.tofix(msg, config.PATHS.PRODUCTPATH, True) # say where searched
+                script_path = "%s_(Not_Found_by_Sat!!)" % script_name
+            prod_info.post_script = script_path
+
+       
+        # Check that the script is executable
+        if os.path.exists(prod_info.post_script) and not os.access(prod_info.post_script, os.X_OK):
+            DBG.tofix("Post install script file is not in 'execute mode'", prod_info.post_script, True)
+
     # Get the full paths of all the patches
     if product_has_patches(prod_info):
         patches = []
@@ -1122,6 +1146,17 @@ def product_has_patches(product_info):
     res = ( "patches" in product_info and len(product_info.patches) > 0 )
     return res
 
+def product_has_post_script(product_info):
+    """Know if a product has a post install script
+    
+    :param product_info Config: The configuration specific to 
+                               the product
+    :return: True if the product has one or more patches
+    :rtype: boolean
+    """   
+    res = ( "post_script" in product_info and len(product_info.post_script) > 0 )
+    return res
+
 def product_has_logo(product_info):
     """Know if a product has a logo (YACSGEN generate)