Salome HOME
fix sat compile from detar problem file sat-product.pyconf evaluation
[tools/sat.git] / commands / clean.py
index 4484cb0656f5dd56c98958eb16da04a8c78eff82..1077297675980897a07e8c4cccf78ab6358fa329 100644 (file)
@@ -16,9 +16,9 @@
 #  License along with this library; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
-import src
+import re
 
-import prepare
+import src
 
 # Compatibility python 2/3 for input function
 # input stays input for python 3 and input = raw_input for python 2
@@ -27,33 +27,35 @@ try:
 except NameError: 
     pass
 
+
 # Define all possible option for the clean command :  sat clean <options>
 parser = src.options.Options()
 parser.add_option('p', 'products', 'list2', 'products',
-    _('products to clean. This option can be'
-    ' passed several time to clean several products.'))
-parser.add_option('s', 'source', 'boolean', 'source', 
-    _("Clean the product source directories."))
+    _('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', 
-    _("Clean the product build directories."))
+    _("Optional: Clean the product build directories."))
 parser.add_option('i', 'install', 'boolean', 'install', 
-    _("Clean the product install directories."))
+    _("Optional: Clean the product install directories."))
 parser.add_option('a', 'all', 'boolean', 'all', 
-    _("Clean the product source, build and install directories."))
+    _("Optional: Clean the product source, build and install directories."))
 parser.add_option('', 'sources_without_dev', 'boolean', 'sources_without_dev', 
-    _("do not clean the products in development mode."))
+    _("Optional: do not clean the products in development mode."))
+
 
 def get_source_directories(products_infos, without_dev):
-    '''Returns the list of directory source paths corresponding to the list of 
-       product information given as input. If without_dev (bool), then
-       the dev products are ignored.
+    """\
+    Returns the list of directory source paths corresponding 
+    to the list of product information given as input.
+    If without_dev (bool) the dev products are ignored.
     
     :param products_infos list: The list of (name, config) corresponding to one
                                 product.
     :param without_dev boolean: If True, then ignore the dev products.
     :return: the list of source paths.
     :rtype: list
-    '''
+    """
     l_dir_source = []
     for __, product_info in products_infos:
         if product_has_dir(product_info, without_dev):
@@ -61,29 +63,31 @@ def get_source_directories(products_infos, without_dev):
     return l_dir_source
 
 def get_build_directories(products_infos):
-    '''Returns the list of directory build paths corresponding to the list of 
-       product information given as input.
+    """\
+    Returns the list of directory build paths corresponding to the list of 
+    product information given as input.
     
     :param products_infos list: The list of (name, config) corresponding to one
                                 product.
     :return: the list of build paths.
     :rtype: list
-    '''
+    """
     l_dir_build = []
     for __, product_info in products_infos:
         if product_has_dir(product_info):
-            l_dir_build.append(src.Path(product_info.build_dir))
+            if "build_dir" in product_info:
+                l_dir_build.append(src.Path(product_info.build_dir))
     return l_dir_build
 
 def get_install_directories(products_infos):
-    '''Returns the list of directory install paths corresponding to the list of 
-       product information given as input.
+    """\
+    Returns the list of directory install paths corresponding to the list of 
+    product information given as input.
     
-    :param products_infos list: The list of (name, config) corresponding to one
-                                product.
+    :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 product_has_dir(product_info):
@@ -91,14 +95,14 @@ def get_install_directories(products_infos):
     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
-       directory corresponding to the product described by product_info.
+    """\
+    Returns a boolean at True if there is a source, build and install
+    directory corresponding to the product described by product_info.
     
     :param products_info Config: The config corresponding to the product.
-    :return: True if there is a source, build and install
-             directory corresponding to the product described by product_info.
+    :return: True if there is a source, build and install directory corresponding to the product described by product_info.
     :rtype: boolean
-    '''
+    """
     if (src.product.product_is_native(product_info) or 
                             src.product.product_is_fixed(product_info)):
         return False
@@ -108,12 +112,11 @@ def product_has_dir(product_info, without_dev=False):
     return True
     
 def suppress_directories(l_paths, logger):
-    '''Suppress the paths given in the list in l_paths.
+    """Suppress the paths given in the list in l_paths.
     
     :param l_paths list: The list of Path to be suppressed
-    :param logger Logger: The logger instance to use for the display and 
-                          logging
-    '''    
+    :param logger Logger: The logger instance to use for the display and logging
+    """    
     for path in l_paths:
         if not path.isdir():
             msg = _("Warning: the path %s does not "
@@ -125,17 +128,23 @@ def suppress_directories(l_paths, logger):
             logger.write('%s\n' % src.printcolors.printc(src.OK_STATUS), 3)
 
 def description():
-    '''method that is called when salomeTools is called with --help option.
+    """method called when salomeTools is called with --help option.
     
     :return: The text to display for the clean command description.
     :rtype: str
-    '''
-    return _("The clean command suppress the source, build, or install "
-             "directories of the application products.")
+    """
+    return _("""\
+The clean command suppress the SOURCES, BUILD or INSTALL directories of the application products.
+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
+""")
   
 def run(args, runner, logger):
-    '''method that is called when salomeTools is called with clean parameter.
-    '''
+    """\
+    method called when salomeTools is called with clean parameter.
+    """
     
     # Parse the options
     (options, args) = parser.parse_args(args)
@@ -143,13 +152,15 @@ def run(args, runner, logger):
     # check that the command has been called with an application
     src.check_config_has_application( runner.cfg )
 
-    products_infos = prepare.get_products_list(options, runner.cfg, logger)
+
+    # Get the list of products to threat
+    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, 
-                                                options.sources_without_dev) +
+                                            options.sources_without_dev) +
                              get_build_directories(products_infos) + 
                              get_install_directories(products_infos))
     else:
@@ -159,10 +170,18 @@ def run(args, runner, logger):
         if options.build:
             l_dir_to_suppress += get_build_directories(products_infos)
             
-        if options.source:
+        if options.sources or options.sources_without_dev:
             l_dir_to_suppress += get_source_directories(products_infos, 
                                                 options.sources_without_dev)
     
+    if len(l_dir_to_suppress) == 0:
+        logger.write(src.printcolors.printcWarning(_("Nothing to suppress\n")))
+        logger.write(_("""\
+Please specify what you want to suppress:
+try 'sat --help clean' and 'sat clean ... --products ... --sources --build --install
+"""))
+        return
+    
     # Check with the user if he really wants to suppress the directories
     if not runner.options.batch:
         logger.write(_("Remove the following directories ?\n"), 1)
@@ -170,9 +189,9 @@ def run(args, runner, logger):
             logger.write("  %s\n" % directory, 1)
         rep = input(_("Are you sure you want to continue? [Yes/No] "))
         if rep.upper() != _("YES"):
-            return
+            return 0
     
     # Suppress the list of paths
     suppress_directories(l_dir_to_suppress, logger)
     
-    return 
\ No newline at end of file
+    return 0