]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
Add the clean command.
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Tue, 19 Apr 2016 12:54:03 +0000 (14:54 +0200)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Tue, 19 Apr 2016 12:54:03 +0000 (14:54 +0200)
15 files changed:
commands/clean.py [new file with mode: 0644]
commands/patch.py
commands/prepare.py
commands/source.py
data/products/KERNEL.pyconf
data/products/PRODUCT_ARCHIVE.pyconf
data/products/PRODUCT_CVS.pyconf
data/products/PRODUCT_DEFAULTVERSION.pyconf
data/products/PRODUCT_DEV.pyconf
data/products/PRODUCT_GIT.pyconf
data/products/PRODUCT_NATIVE.pyconf
data/products/PRODUCT_SVN.pyconf
data/products/PRODUCT_UNKNOWN.pyconf
salomeTools.py
src/product.py

diff --git a/commands/clean.py b/commands/clean.py
new file mode 100644 (file)
index 0000000..4484cb0
--- /dev/null
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+#  Copyright (C) 2010-2012  CEA/DEN
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  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 prepare
+
+# Compatibility python 2/3 for input function
+# input stays input for python 3 and input = raw_input for python 2
+try: 
+    input = raw_input
+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."))
+parser.add_option('b', 'build', 'boolean', 'build', 
+    _("Clean the product build directories."))
+parser.add_option('i', 'install', 'boolean', 'install', 
+    _("Clean the product install directories."))
+parser.add_option('a', 'all', 'boolean', 'all', 
+    _("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."))
+
+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.
+    
+    :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):
+            l_dir_source.append(src.Path(product_info.source_dir))
+    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.
+    
+    :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))
+    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.
+    
+    :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):
+            l_dir_install.append(src.Path(product_info.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
+       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.
+    :rtype: boolean
+    '''
+    if (src.product.product_is_native(product_info) or 
+                            src.product.product_is_fixed(product_info)):
+        return False
+    if without_dev:
+        if src.product.product_is_dev(product_info):
+            return False
+    return True
+    
+def suppress_directories(l_paths, logger):
+    '''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
+    '''    
+    for path in l_paths:
+        if not path.isdir():
+            msg = _("Warning: the path %s does not "
+                    "exists (or is not a directory)\n" % path.__str__())
+            logger.write(src.printcolors.printcWarning(msg), 1)
+        else:
+            logger.write(_("Removing %s ...") % path.__str__())
+            path.rm()
+            logger.write('%s\n' % src.printcolors.printc(src.OK_STATUS), 3)
+
+def description():
+    '''method that is 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.")
+  
+def run(args, runner, logger):
+    '''method that is called when salomeTools is called with clean parameter.
+    '''
+    
+    # Parse the options
+    (options, args) = parser.parse_args(args)
+
+    # 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)
+
+    # 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) +
+                             get_build_directories(products_infos) + 
+                             get_install_directories(products_infos))
+    else:
+        if options.install:
+            l_dir_to_suppress += get_install_directories(products_infos)
+        
+        if options.build:
+            l_dir_to_suppress += get_build_directories(products_infos)
+            
+        if options.source:
+            l_dir_to_suppress += get_source_directories(products_infos, 
+                                                options.sources_without_dev)
+    
+    # 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)
+        for directory in l_dir_to_suppress:
+            logger.write("  %s\n" % directory, 1)
+        rep = input(_("Are you sure you want to continue? [Yes/No] "))
+        if rep.upper() != _("YES"):
+            return
+    
+    # Suppress the list of paths
+    suppress_directories(l_dir_to_suppress, logger)
+    
+    return 
\ No newline at end of file
index e118708ee41652d2faa0c59b36935bfdbb6d8737..cf323c90547c9e12f91e14f4948e4eb93ce05398 100644 (file)
@@ -22,13 +22,11 @@ import subprocess
 import src
 import prepare
 
-# Define all possible option for log command :  sat log <options>
+# Define all possible option for patch command :  sat patch <options>
 parser = src.options.Options()
 parser.add_option('p', 'product', 'list2', 'products',
     _('products to get the sources. This option can be'
     ' passed several time to get the sources of several products.'))
-parser.add_option('', 'no_sample', 'boolean', 'no_sample', 
-    _("do not get sources from sample products."))
 
 def apply_patch(config, product_info, logger):
     '''The method called to apply patches on a product
@@ -126,8 +124,8 @@ def run(args, runner, logger):
     logger.write('Patching sources of the application %s\n' % 
                 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
 
-    src.printcolors.print_value(logger, 'out_dir', 
-                                runner.cfg.APPLICATION.out_dir, 2)
+    src.printcolors.print_value(logger, 'workdir', 
+                                runner.cfg.APPLICATION.workdir, 2)
     logger.write("\n", 2, False)
 
     # Get the products list with products informations regarding the options
index ece313e64882ca14bcbf0c978ea8f9af2e1c48ec..e3c1273ea5faf6191f558a21790475f9b030b8c1 100644 (file)
 
 import src
 
-# Define all possible option for log command :  sat log <options>
+# Define all possible option for prepare command :  sat prepare <options>
 parser = src.options.Options()
 parser.add_option('p', 'product', 'list2', 'products',
     _('products to prepare. This option can be'
     ' passed several time to prepare several products.'))
-parser.add_option('', 'no_sample', 'boolean', 'no_sample', 
-    _("do not prepare sample products."))
 parser.add_option('f', 'force', 'boolean', 'force', 
     _("force to prepare the products in development mode."))
 parser.add_option('f', 'force_patch', 'boolean', 'force_patch', 
@@ -58,24 +56,6 @@ def get_products_list(options, cfg, logger):
     # Construct the list of tuple containing 
     # the products name and their definition
     products_infos = src.product.get_products_infos(products, cfg)
-
-    # if the --no_sample option is invoked, suppress the sample products from 
-    # the list
-    if options.no_sample:
-        
-        lproducts_sample = [p for p in products_infos if src.product.product_is_sample(p[1])]
-        
-        products_infos = [p for p in products_infos if p not in lproducts_sample]
-
-        if len(lproducts_sample) > 0:
-            msg = "Ignoring the following sample products:\n"
-            logger.write(src.printcolors.printcWarning(_(msg)), 1)
-        for i, product in enumerate(lproducts_sample):
-            end_text = ', '
-            if i+1 == len(lproducts_sample):
-                end_text = '\n'
-                
-            logger.write(product[0] + end_text, 1)
     
     return products_infos
 
@@ -113,12 +93,8 @@ def run(args, runner, logger):
     else:
         for p_name, __ in products_infos:
             args_product_opt += ',' + p_name
-    
-    args_sample = ''
-    if options.no_sample:
-        args_sample = ' --no_sample'
-    
-    args_source = args_appli + args_product_opt + args_sample
+      
+    args_source = args_appli + args_product_opt
         
     if options.force:
         args_source += ' --force'
@@ -158,7 +134,7 @@ def run(args, runner, logger):
         logger.write(msg)
         res_patch = 0
     else:
-        args_patch = args_appli + args_product_opt + args_sample
+        args_patch = args_appli + args_product_opt
         
         # Call the source command that gets the source
         res_patch = runner.patch(args_patch)
index 056f2c823079df8b8338295b8903a97252216039..c13335be6b93cdd9df8cab419138803ba006f55d 100644 (file)
@@ -22,13 +22,11 @@ import shutil
 import src
 import prepare
 
-# Define all possible option for log command :  sat log <options>
+# Define all possible option for patch command :  sat patch <options>
 parser = src.options.Options()
 parser.add_option('p', 'product', 'list2', 'products',
     _('products from which to get the sources. This option can be'
     ' passed several time to get the sources of several products.'))
-parser.add_option('', 'no_sample', 'boolean', 'no_sample', 
-    _("do not get sources from sample products."))
 parser.add_option('f', 'force', 'boolean', 'force', 
     _("force to remove the sources before getting them (in development mode only)."))
 
@@ -418,8 +416,8 @@ def run(args, runner, logger):
     # Print some informations
     logger.write(_('Getting sources of the application %s\n') % 
                 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
-    src.printcolors.print_value(logger, 'out_dir', 
-                                runner.cfg.APPLICATION.out_dir, 2)
+    src.printcolors.print_value(logger, 'workdir', 
+                                runner.cfg.APPLICATION.workdir, 2)
     logger.write("\n", 2, False)
     
     # Get the force option if it was passed
index 7bb456e231ea356ebd4121ac3955024182288659..a362eca6b09b61f1b781d237f35f57c725e279c5 100644 (file)
@@ -18,6 +18,7 @@ KERNEL_V7_7_1 :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    #install_dir : "base"
 }
index 04250d8a1df455800ca2df3e9cc6b0c6082696ad..079dede8a662edadaa8efe7a6812e03185b05201 100644 (file)
@@ -17,8 +17,8 @@ PRODUCT_ARCHIVE :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
     patches : ['/home/salome/salomeTools-4.3.7/data/compil_scripts/patches/scipy.patch', '/export/home/serioja/MODULE_ARCHIVE.patch']
 }
 
@@ -41,7 +41,7 @@ PRODUCT_ARCHIVE_4_4_2 :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
     patches : []
 }
\ No newline at end of file
index a7f6e12f088b901ad3347cc457afe545e18517b9..5bff5dbbc6044f9fde37369f59095efec89701d8 100644 (file)
@@ -28,6 +28,6 @@ PRODUCT_CVS_V6_7_0 :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
 }
\ No newline at end of file
index bd0c7e48f7e2876e81209918d60a96fd85655849..fa7ca91b8a5bf6d165eb0ef081586bc78c9a82a9 100644 (file)
@@ -28,6 +28,6 @@ MODULE_DEFAULTVERSION :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
 }
\ No newline at end of file
index 7666c909a679fa45462d7fcdb1aed53e2d9a4668..ebfefeaeec937ae0ba7501cf77dde5c1819c54b2 100644 (file)
@@ -18,7 +18,7 @@ PRODUCT_DEV :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
     patches : [$VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'mypatch.patch']
 }
\ No newline at end of file
index e611198bfb07bef970a773384d6c2c3db0d4a542..4637aba3335ab15592769fb0ae2dbb2a05fcf035 100644 (file)
@@ -18,7 +18,7 @@ PRODUCT_GIT :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
     patches : []
 }
\ No newline at end of file
index 3de0e1f338fe7b2bc5e7ee9adaf9c28a3ce8564a..52788cc0566e286766ecdaeb51bbb77b63c0af19 100644 (file)
@@ -26,6 +26,6 @@ MODULE_NATIVE :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
 }
\ No newline at end of file
index 9a657b9506d449e4e9c0c7bf43750155a3826463..bca3455b7db775d575f830c9ae7a44efe382d24d 100644 (file)
@@ -26,6 +26,6 @@ PRODUCT_SVN :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
 }
\ No newline at end of file
index 6821d4b5b2e15e39e725e89a31ea6402bee2e707..cefd2ee6f574a642bd62b679c69806d075d9e16a 100644 (file)
@@ -13,6 +13,6 @@ PRODUCT_UNKNOWN :
     depend : []
     opt_depend : []
     type : "sample"
-    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
-    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
 }
\ No newline at end of file
index 09267ba5c017ae0da6ac7bce1f4751641485768d..9e3f7a8b1e7e06f43c558430b799da22a13f5523 100755 (executable)
@@ -77,6 +77,8 @@ parser.add_option('g', 'debug', 'boolean', 'debug_mode',
                   _("run salomeTools in debug mode."))
 parser.add_option('v', 'verbose', 'int', "output_verbose_level", 
                   _("change output verbose level (default is 3)."))
+parser.add_option('b', 'batch', 'boolean', "batch", 
+                  _("batch mode (no question)."))
 
 class Sat(object):
     '''The main class that stores all the commands of salomeTools
index ec2f7547758ef3eab496c6f104b15a077959ee15..a5c5fb17fb72bf370eda4197386e36b083291a2f 100644 (file)
@@ -19,6 +19,8 @@
    relative to the product notion of salomeTools
 '''
 
+import os
+
 import src
 
 AVAILABLE_VCS = ['git', 'svn', 'cvs']
@@ -119,7 +121,14 @@ def get_product_config(config, product_name):
     if prod_info is not None:
         prod_info.debug = debug
         prod_info.dev = dev
-        
+     
+    # Set the install_dir key
+    if "install_dir" not in prod_info:
+        # Set it to the default value (in application directory)
+        prod_info.install_dir = os.path.join(config.APPLICATION.workdir,
+                                            "INSTALL",
+                                            prod_info.name)
+       
     return prod_info
 
 def get_products_infos(lproducts, config):