3 # Copyright (C) 2010-2012 CEA/DEN
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # Compatibility python 2/3 for input function
24 # input stays input for python 3 and input = raw_input for python 2
30 # Define all possible option for the clean command : sat clean <options>
31 parser = src.options.Options()
32 parser.add_option('p', 'products', 'list2', 'products',
33 _('products to clean. This option can be'
34 ' passed several time to clean several products.'))
35 parser.add_option('s', 'sources', 'boolean', 'sources',
36 _("Clean the product source directories."))
37 parser.add_option('b', 'build', 'boolean', 'build',
38 _("Clean the product build directories."))
39 parser.add_option('i', 'install', 'boolean', 'install',
40 _("Clean the product install directories."))
41 parser.add_option('a', 'all', 'boolean', 'all',
42 _("Clean the product source, build and install directories."))
43 parser.add_option('', 'sources_without_dev', 'boolean', 'sources_without_dev',
44 _("do not clean the products in development mode."))
46 def get_source_directories(products_infos, without_dev):
47 '''Returns the list of directory source paths corresponding to the list of
48 product information given as input. If without_dev (bool), then
49 the dev products are ignored.
51 :param products_infos list: The list of (name, config) corresponding to one
53 :param without_dev boolean: If True, then ignore the dev products.
54 :return: the list of source paths.
58 for __, product_info in products_infos:
59 if product_has_dir(product_info, without_dev):
60 l_dir_source.append(src.Path(product_info.source_dir))
63 def get_build_directories(products_infos):
64 '''Returns the list of directory build paths corresponding to the list of
65 product information given as input.
67 :param products_infos list: The list of (name, config) corresponding to one
69 :return: the list of build paths.
73 for __, product_info in products_infos:
74 if product_has_dir(product_info):
75 l_dir_build.append(src.Path(product_info.build_dir))
78 def get_install_directories(products_infos):
79 '''Returns the list of directory install paths corresponding to the list of
80 product information given as input.
82 :param products_infos list: The list of (name, config) corresponding to one
84 :return: the list of install paths.
88 for __, product_info in products_infos:
89 if product_has_dir(product_info):
90 l_dir_install.append(src.Path(product_info.install_dir))
93 def product_has_dir(product_info, without_dev=False):
94 '''Returns a boolean at True if there is a source, build and install
95 directory corresponding to the product described by product_info.
97 :param products_info Config: The config corresponding to the product.
98 :return: True if there is a source, build and install
99 directory corresponding to the product described by product_info.
102 if (src.product.product_is_native(product_info) or
103 src.product.product_is_fixed(product_info)):
106 if src.product.product_is_dev(product_info):
110 def suppress_directories(l_paths, logger):
111 '''Suppress the paths given in the list in l_paths.
113 :param l_paths list: The list of Path to be suppressed
114 :param logger Logger: The logger instance to use for the display and
119 msg = _("Warning: the path %s does not "
120 "exists (or is not a directory)\n" % path.__str__())
121 logger.write(src.printcolors.printcWarning(msg), 1)
123 logger.write(_("Removing %s ...") % path.__str__())
125 logger.write('%s\n' % src.printcolors.printc(src.OK_STATUS), 3)
128 '''method that is called when salomeTools is called with --help option.
130 :return: The text to display for the clean command description.
133 return _("The clean command suppress the source, build, or install "
134 "directories of the application products.")
136 def run(args, runner, logger):
137 '''method that is called when salomeTools is called with clean parameter.
141 (options, args) = parser.parse_args(args)
143 # check that the command has been called with an application
144 src.check_config_has_application( runner.cfg )
146 # Get the list of products to threat
147 products_infos = prepare.get_products_list(options, runner.cfg, logger)
149 # Construct the list of directories to suppress
150 l_dir_to_suppress = []
152 l_dir_to_suppress += (get_source_directories(products_infos,
153 options.sources_without_dev) +
154 get_build_directories(products_infos) +
155 get_install_directories(products_infos))
158 l_dir_to_suppress += get_install_directories(products_infos)
161 l_dir_to_suppress += get_build_directories(products_infos)
163 if options.sources or options.sources_without_dev:
164 l_dir_to_suppress += get_source_directories(products_infos,
165 options.sources_without_dev)
167 if len(l_dir_to_suppress) == 0:
168 logger.write(src.printcolors.printcWarning(_("Nothing to suppress\n")))
171 # Check with the user if he really wants to suppress the directories
172 if not runner.options.batch:
173 logger.write(_("Remove the following directories ?\n"), 1)
174 for directory in l_dir_to_suppress:
175 logger.write(" %s\n" % directory, 1)
176 rep = input(_("Are you sure you want to continue? [Yes/No] "))
177 if rep.upper() != _("YES"):
180 # Suppress the list of paths
181 suppress_directories(l_dir_to_suppress, logger)