Salome HOME
decode pip version
[tools/sat.git] / commands / clean.py
index b12182b492b5897384b14e08808997787e778af6..070b87517cbed510c3d216b23ed1ca82005c51a5 100644 (file)
@@ -17,6 +17,7 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
 import re
+import os
 
 import src
 
@@ -27,69 +28,28 @@ try:
 except NameError: 
     pass
 
-PROPERTY_EXPRESSION = "^.+:.+$"
 
 # Define all possible option for the clean command :  sat clean <options>
 parser = src.options.Options()
 parser.add_option('p', 'products', 'list2', 'products',
-    _('Optional: Products to clean. This option can be'
-    ' passed several time to clean several products.'))
-parser.add_option('', 'properties', 'string', 'properties',
-    _('Optional: Filter the products by their properties.\n\tSyntax: '
-      '--properties <property>:<value>'))
-parser.add_option('s', 'sources', 'boolean', 'sources', 
+    _('Optional: Products to clean. This option accepts a comma separated list.'))
+parser.add_option('s', 'sources', 'boolean', 'sources',
     _("Optional: Clean the product source directories."))
 parser.add_option('b', 'build', 'boolean', 'build', 
     _("Optional: Clean the product build directories."))
 parser.add_option('i', 'install', 'boolean', 'install', 
     _("Optional: Clean the product install directories."))
+parser.add_option('g', 'generated', 'boolean', 'generated', 
+    _("Optional: Clean source, build and install directories for generated products."))
+parser.add_option('', 'package', 'boolean', 'package', 
+    _("Optional: Clean packages produced by sat package command."))
 parser.add_option('a', 'all', 'boolean', 'all', 
     _("Optional: Clean the product source, build and install directories."))
 parser.add_option('', 'sources_without_dev', 'boolean', 'sources_without_dev', 
     _("Optional: do not clean the products in development mode."))
 
-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 get_source_directories(products_infos, without_dev):
+def get_source_directories(config, products_infos, without_dev):
     """\
     Returns the list of directory source paths corresponding 
     to the list of product information given as input.
@@ -104,7 +64,10 @@ def get_source_directories(products_infos, without_dev):
     l_dir_source = []
     for __, product_info in products_infos:
         if product_has_dir(product_info, without_dev):
-            l_dir_source.append(src.Path(product_info.source_dir))
+            # we do not clean source dirs of pip products when pip is activated
+            if not ( src.appli_test_property(config,"pip", "yes") and\
+                     src.product.product_test_property(product_info,"pip", "yes") ) :
+                l_dir_source.append(src.Path(product_info.source_dir))
     return l_dir_source
 
 def get_build_directories(products_infos):
@@ -124,7 +87,7 @@ def get_build_directories(products_infos):
                 l_dir_build.append(src.Path(product_info.build_dir))
     return l_dir_build
 
-def get_install_directories(products_infos):
+def get_install_directories(config, products_infos):
     """\
     Returns the list of directory install paths corresponding to the list of 
     product information given as input.
@@ -136,9 +99,52 @@ def get_install_directories(products_infos):
     l_dir_install = []
     for __, product_info in products_infos:
         if product_has_dir(product_info):
-            l_dir_install.append(src.Path(product_info.install_dir))
+            # we do not clean pip products installed in python install dir
+            if not ( src.appli_test_property(config,"pip", "yes") and\
+                     src.product.product_test_property(product_info, "pip", "yes") and\
+                     src.appli_test_property(config,"pip_install_dir", "python") ) :
+                l_dir_install.append(src.Path(product_info.install_dir))
     return l_dir_install
 
+def get_package_directory(config):
+    """\
+    Returns the package directory name corresponding to the sat package command
+    
+    :param config Config: The global configuration
+    :return: a list containing the PACKAGE full path.
+    :rtype: list
+    """
+    return [src.Path(os.path.join(config.APPLICATION.workdir, "PACKAGE"))]
+
+def get_generated_directories(config, products_infos):
+    """\
+    Returns the list of directories (source, build, install) corresponding to the 
+    list of products information given as input.
+    Nothing is returned for non generated products (those with...)
+    
+    :param products_infos list: The list of (name, config) corresponding to one product.
+    :return: the list of install paths.
+    :rtype: list
+    """
+    l_dir_install = []
+    for __, product_info in products_infos:
+        if not src.product.product_is_generated(product_info):
+            continue
+        workdir = config.APPLICATION.workdir
+        compo = product_info.component_name
+        generate_dir = os.path.join(workdir, "GENERATED")
+        source_dir = os.path.join(generate_dir, compo + "_SRC")
+        build_dir = os.path.join(os.path.join(workdir, "BUILD"), compo)
+        install_dir = os.path.join(workdir, config.INTERNAL.config.install_dir,
+                                   compo)
+        l_dir_install.append(src.Path(source_dir))
+        l_dir_install.append(src.Path(build_dir))
+        l_dir_install.append(src.Path(install_dir))
+        
+    return l_dir_install
+
+
+
 def product_has_dir(product_info, without_dev=False):
     """\
     Returns a boolean at True if there is a source, build and install
@@ -183,7 +189,7 @@ The clean command suppress the SOURCES, BUILD or INSTALL directories of the appl
 Use the options to define what directories you want to suppress and to set the list of products
 
 example:
->> sat clean SALOME-xx --build --install --properties is_salome_module:yes
+>> sat clean SALOME-xx --build --install --properties is_SALOME_module:yes
 """)
   
 def run(args, runner, logger):
@@ -197,37 +203,34 @@ 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
-            
 
     # Get the list of products to threat
-    products_infos = get_products_list(options, runner.cfg, logger)
+    products_infos = src.product.get_products_list(options, runner.cfg, logger)
 
     # Construct the list of directories to suppress
     l_dir_to_suppress = []
     if options.all:
-        l_dir_to_suppress += (get_source_directories(products_infos, 
+        l_dir_to_suppress += (get_source_directories(runner.cfg, products_infos, 
                                             options.sources_without_dev) +
                              get_build_directories(products_infos) + 
-                             get_install_directories(products_infos))
+                             get_install_directories(runner.cfg, products_infos) + 
+                             get_generated_directories(runner.cfg, products_infos) + 
+                             get_package_directory(runner.cfg) )
     else:
         if options.install:
-            l_dir_to_suppress += get_install_directories(products_infos)
+            l_dir_to_suppress += get_install_directories(runner.cfg, products_infos)
         
         if options.build:
             l_dir_to_suppress += get_build_directories(products_infos)
             
         if options.sources or options.sources_without_dev:
-            l_dir_to_suppress += get_source_directories(products_infos, 
+            l_dir_to_suppress += get_source_directories(runner.cfg, products_infos, 
                                                 options.sources_without_dev)
+        if options.generated:
+            l_dir_to_suppress += get_generated_directories(runner.cfg, products_infos)
+
+        if options.package:
+            l_dir_to_suppress += get_package_directory(runner.cfg)
     
     if len(l_dir_to_suppress) == 0:
         logger.write(src.printcolors.printcWarning(_("Nothing to suppress\n")))