Salome HOME
release notes 5.5 5.0 part 1
[tools/sat.git] / commands / clean.py
index 1077297675980897a07e8c4cccf78ab6358fa329..57c292031321ba0d43699198960166c990edb188 100644 (file)
@@ -17,6 +17,7 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
 import re
+import os
 
 import src
 
@@ -38,6 +39,10 @@ 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', 
@@ -94,6 +99,44 @@ def get_install_directories(products_infos):
             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(os.path.join(workdir, "INSTALL"), 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
@@ -138,7 +181,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):
@@ -162,7 +205,9 @@ def run(args, runner, logger):
         l_dir_to_suppress += (get_source_directories(products_infos, 
                                             options.sources_without_dev) +
                              get_build_directories(products_infos) + 
-                             get_install_directories(products_infos))
+                             get_install_directories(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)
@@ -173,6 +218,11 @@ def run(args, runner, logger):
         if options.sources or options.sources_without_dev:
             l_dir_to_suppress += get_source_directories(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")))