Salome HOME
ajout option d'impression des graphes de dépendance
[tools/sat.git] / commands / prepare.py
index eb05265ec4685dcbe73a11a59724267e8ef1a909..66f77e0606c7a09372af5295fe17f6a5deef33b2 100644 (file)
@@ -23,62 +23,21 @@ import pprint as PP
 import src
 import src.debug as DBG
 
-PROPERTY_EXPRESSION = "^.+:.+$"
 
 # Define all possible option for prepare command :  sat prepare <options>
 parser = src.options.Options()
 parser.add_option('p', 'products', 'list2', 'products',
-    _('Optional: products to prepare. This option can be'
-    ' passed several time to prepare several products.'))
-parser.add_option('', 'properties', 'string', 'properties',
-    _('Optional: Filter the products by their properties.\n\tSyntax: '
-      '--properties <property>:<value>'))
-parser.add_option('f', 'force', 'boolean', 'force', 
+    _('Optional: products to prepare. This option accepts a comma separated list.'))
+parser.add_option('f', 'force', 'boolean', 'force',
     _("Optional: force to prepare the products in development mode."))
 parser.add_option('', 'force_patch', 'boolean', 'force_patch', 
     _("Optional: force to apply patch to the products in development mode."))
+parser.add_option('c', 'complete', 'boolean', 'complete',
+    _("Optional: completion mode, only prepare products not present in SOURCES dir."),
+    False)
 
-def get_products_list(options, cfg, logger):
-    '''method that gives the product list with their informations from 
-       configuration regarding the passed options.
-    
-    :param options Options: The Options instance that stores the commands 
-                            arguments
-    :param config Config: The global configuration
-    :param logger Logger: The logger instance to use for the display and logging
-    :return: The list of (product name, product_informations).
-    :rtype: List
-    '''
-    # Get the products to be prepared, regarding the options
-    if options.products is None:
-        # No options, get all products sources
-        products = cfg.APPLICATION.products
-    else:
-        # if option --products, check that all products of the command line
-        # are present in the application.
-        products = options.products
-        for p in products:
-            if p not in cfg.APPLICATION.products:
-                raise src.SatException(_("Product %(product)s "
-                            "not defined in application %(application)s") %
-                        { 'product': p, 'application': cfg.VARS.application} )
-    
-    # Construct the list of tuple containing 
-    # the products name and their definition
-    products_infos = src.product.get_products_infos(products, cfg)
-    
-    # if the property option was passed, filter the list
-    if options.properties:
-        [prop, value] = options.properties.split(":")
-        products_infos = [(p_name, p_info) for 
-                          (p_name, p_info) in products_infos 
-                          if "properties" in p_info and 
-                          prop in p_info.properties and 
-                          p_info.properties[prop] == value]
-        
-    return products_infos
 
-def find_products_already_getted(l_products):
+def find_products_already_prepared(l_products):
     '''function that returns the list of products that have an existing source 
        directory.
     
@@ -90,7 +49,7 @@ def find_products_already_getted(l_products):
     l_res = []
     for p_name_p_cfg in l_products:
         __, prod_cfg = p_name_p_cfg
-        if os.path.exists(prod_cfg.source_dir):
+        if "source_dir" in prod_cfg and os.path.exists(prod_cfg.source_dir):
             l_res.append(p_name_p_cfg)
     return l_res
 
@@ -129,17 +88,7 @@ def run(args, runner, logger):
     # check that the command has been called with an application
     src.check_config_has_application( runner.cfg )
 
-    # Verify the --properties option
-    if options.properties:
-        oExpr = re.compile(PROPERTY_EXPRESSION)
-        if not oExpr.search(options.properties):
-            msg = _('WARNING: the "--properties" options must have the '
-                    'following syntax:\n--properties <property>:<value>')
-            logger.write(src.printcolors.printcWarning(msg), 1)
-            logger.write("\n", 1)
-            options.properties = None
-
-    products_infos = get_products_list(options, runner.cfg, logger)
+    products_infos = src.product.get_products_list(options, runner.cfg, logger)
 
     # Construct the arguments to pass to the clean, source and patch commands
     args_appli = runner.cfg.VARS.application + " "  # useful whitespace
@@ -148,7 +97,21 @@ def run(args, runner, logger):
     else: # no product interpeted as all products
         listProd = [name for name, tmp in products_infos]
 
-    DBG.write("prepare products", sorted(listProd))
+    if options.complete:
+        # remove products that are already prepared 'completion mode)
+        pi_already_prepared=find_products_already_prepared(products_infos)
+        l_already_prepared = [i for i, tmp in pi_already_prepared]
+        newList, removedList = removeInList(listProd, l_already_prepared)
+        listProd = newList
+        if len(newList) == 0 and len(removedList) > 0 :
+            msg = "\nAll the products are already installed, do nothing!\n"
+            logger.write(src.printcolors.printcWarning(msg), 1)
+            return 0
+        if len(removedList) > 0 :
+            msg = "\nList of already prepared products that are skipped : %s\n" % ",".join(removedList)
+            logger.write(msg, 3)
+        
+
     args_product_opt = '--products ' + ",".join(listProd)
     do_source = (len(listProd) > 0)
 
@@ -156,7 +119,7 @@ def run(args, runner, logger):
     ldev_products = [p for p in products_infos if src.product.product_is_dev(p[1])]
     newList = listProd # default
     if not options.force and len(ldev_products) > 0:
-        l_products_not_getted = find_products_already_getted(ldev_products)
+        l_products_not_getted = find_products_already_prepared(ldev_products)
         listNot = [i for i, tmp in l_products_not_getted]
         newList, removedList = removeInList(listProd, listNot)
         if len(removedList) > 0:
@@ -191,10 +154,10 @@ Use the --force_patch option to overwrite it.
     args_source = args_appli + args_product_opt  
     args_patch = args_appli + args_product_opt_patch
       
-    # Initialize the results to a failing status
-    res_clean = 1
-    res_source = 1
-    res_patch = 1
+    # Initialize the results to a running status
+    res_clean = 0
+    res_source = 0
+    res_patch = 0
     
     # Call the commands using the API
     if do_clean: