From 008b47c0acae2b56dafd2533aa89e5a57df767e3 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Tue, 19 Apr 2016 14:54:03 +0200 Subject: [PATCH] Add the clean command. --- commands/clean.py | 178 ++++++++++++++++++++ commands/patch.py | 8 +- commands/prepare.py | 32 +--- commands/source.py | 8 +- data/products/KERNEL.pyconf | 5 +- data/products/PRODUCT_ARCHIVE.pyconf | 8 +- data/products/PRODUCT_CVS.pyconf | 4 +- data/products/PRODUCT_DEFAULTVERSION.pyconf | 4 +- data/products/PRODUCT_DEV.pyconf | 4 +- data/products/PRODUCT_GIT.pyconf | 4 +- data/products/PRODUCT_NATIVE.pyconf | 4 +- data/products/PRODUCT_SVN.pyconf | 4 +- data/products/PRODUCT_UNKNOWN.pyconf | 4 +- salomeTools.py | 2 + src/product.py | 11 +- 15 files changed, 221 insertions(+), 59 deletions(-) create mode 100644 commands/clean.py diff --git a/commands/clean.py b/commands/clean.py new file mode 100644 index 0000000..4484cb0 --- /dev/null +++ b/commands/clean.py @@ -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 +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 diff --git a/commands/patch.py b/commands/patch.py index e118708..cf323c9 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -22,13 +22,11 @@ import subprocess import src import prepare -# Define all possible option for log command : sat log +# Define all possible option for patch command : sat patch 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 diff --git a/commands/prepare.py b/commands/prepare.py index ece313e..e3c1273 100644 --- a/commands/prepare.py +++ b/commands/prepare.py @@ -18,13 +18,11 @@ import src -# Define all possible option for log command : sat log +# Define all possible option for prepare command : sat prepare 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) diff --git a/commands/source.py b/commands/source.py index 056f2c8..c13335b 100644 --- a/commands/source.py +++ b/commands/source.py @@ -22,13 +22,11 @@ import shutil import src import prepare -# Define all possible option for log command : sat log +# Define all possible option for patch command : sat patch 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 diff --git a/data/products/KERNEL.pyconf b/data/products/KERNEL.pyconf index 7bb456e..a362eca 100644 --- a/data/products/KERNEL.pyconf +++ b/data/products/KERNEL.pyconf @@ -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" } diff --git a/data/products/PRODUCT_ARCHIVE.pyconf b/data/products/PRODUCT_ARCHIVE.pyconf index 04250d8..079dede 100644 --- a/data/products/PRODUCT_ARCHIVE.pyconf +++ b/data/products/PRODUCT_ARCHIVE.pyconf @@ -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 diff --git a/data/products/PRODUCT_CVS.pyconf b/data/products/PRODUCT_CVS.pyconf index a7f6e12..5bff5db 100644 --- a/data/products/PRODUCT_CVS.pyconf +++ b/data/products/PRODUCT_CVS.pyconf @@ -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 diff --git a/data/products/PRODUCT_DEFAULTVERSION.pyconf b/data/products/PRODUCT_DEFAULTVERSION.pyconf index bd0c7e4..fa7ca91 100644 --- a/data/products/PRODUCT_DEFAULTVERSION.pyconf +++ b/data/products/PRODUCT_DEFAULTVERSION.pyconf @@ -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 diff --git a/data/products/PRODUCT_DEV.pyconf b/data/products/PRODUCT_DEV.pyconf index 7666c90..ebfefea 100644 --- a/data/products/PRODUCT_DEV.pyconf +++ b/data/products/PRODUCT_DEV.pyconf @@ -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 diff --git a/data/products/PRODUCT_GIT.pyconf b/data/products/PRODUCT_GIT.pyconf index e611198..4637aba 100644 --- a/data/products/PRODUCT_GIT.pyconf +++ b/data/products/PRODUCT_GIT.pyconf @@ -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 diff --git a/data/products/PRODUCT_NATIVE.pyconf b/data/products/PRODUCT_NATIVE.pyconf index 3de0e1f..52788cc 100644 --- a/data/products/PRODUCT_NATIVE.pyconf +++ b/data/products/PRODUCT_NATIVE.pyconf @@ -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 diff --git a/data/products/PRODUCT_SVN.pyconf b/data/products/PRODUCT_SVN.pyconf index 9a657b9..bca3455 100644 --- a/data/products/PRODUCT_SVN.pyconf +++ b/data/products/PRODUCT_SVN.pyconf @@ -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 diff --git a/data/products/PRODUCT_UNKNOWN.pyconf b/data/products/PRODUCT_UNKNOWN.pyconf index 6821d4b..cefd2ee 100644 --- a/data/products/PRODUCT_UNKNOWN.pyconf +++ b/data/products/PRODUCT_UNKNOWN.pyconf @@ -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 diff --git a/salomeTools.py b/salomeTools.py index 09267ba..9e3f7a8 100755 --- a/salomeTools.py +++ b/salomeTools.py @@ -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 diff --git a/src/product.py b/src/product.py index ec2f754..a5c5fb1 100644 --- a/src/product.py +++ b/src/product.py @@ -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): -- 2.39.2