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
22 # Compatibility python 2/3 for input function
23 # 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()
37 _("Optional: Products to clean. This option accepts a comma separated list."),
44 _("Optional: Clean the product source directories."),
51 _("Optional: Clean the product build directories."),
58 _("Optional: Clean the product install directories."),
65 _("Optional: Clean source, build and install directories for generated products."),
72 _("Optional: Clean packages produced by sat package command."),
79 _("Optional: Clean the product source, build and install directories."),
83 "sources_without_dev",
85 "sources_without_dev",
86 _("Optional: do not clean the products in development mode."),
90 def get_source_directories(config, products_infos, without_dev):
92 Returns the list of directory source paths corresponding
93 to the list of product information given as input.
94 If without_dev (bool) the dev products are ignored.
96 :param products_infos list: The list of (name, config) corresponding to one
98 :param without_dev boolean: If True, then ignore the dev products.
99 :return: the list of source paths.
103 for __, product_info in products_infos:
104 if product_has_dir(product_info, without_dev):
105 # we do not clean source dirs of pip products when pip is activated
107 src.appli_test_property(config, "pip", "yes")
108 and src.product.product_test_property(product_info, "pip", "yes")
110 l_dir_source.append(src.Path(product_info.source_dir))
114 def get_build_directories(products_infos):
116 Returns the list of directory build paths corresponding to the list of
117 product information given as input.
119 :param products_infos list: The list of (name, config) corresponding to one
121 :return: the list of build paths.
125 for __, product_info in products_infos:
126 if product_has_dir(product_info):
127 if "build_dir" in product_info:
128 l_dir_build.append(src.Path(product_info.build_dir))
132 def get_install_directories(config, products_infos):
134 Returns the list of directory install paths corresponding to the list of
135 product information given as input.
137 :param products_infos list: The list of (name, config) corresponding to one product.
138 :return: the list of install paths.
142 for __, product_info in products_infos:
143 if product_has_dir(product_info):
144 # we do not clean pip products installed in python install dir
146 src.appli_test_property(config, "pip", "yes")
147 and src.product.product_test_property(product_info, "pip", "yes")
148 and src.appli_test_property(config, "pip_install_dir", "python")
150 l_dir_install.append(src.Path(product_info.install_dir))
154 def get_package_directory(config):
156 Returns the package directory name corresponding to the sat package command
158 :param config Config: The global configuration
159 :return: a list containing the PACKAGE full path.
162 return [src.Path(os.path.join(config.APPLICATION.workdir, "PACKAGE"))]
165 def get_generated_directories(config, products_infos):
167 Returns the list of directories (source, build, install) corresponding to the
168 list of products information given as input.
169 Nothing is returned for non generated products (those with...)
171 :param products_infos list: The list of (name, config) corresponding to one product.
172 :return: the list of install paths.
176 for __, product_info in products_infos:
177 if not src.product.product_is_generated(product_info):
179 workdir = config.APPLICATION.workdir
180 compo = product_info.component_name
181 generate_dir = os.path.join(workdir, "GENERATED")
182 source_dir = os.path.join(generate_dir, compo + "_SRC")
183 build_dir = os.path.join(os.path.join(workdir, "BUILD"), compo)
184 install_dir = os.path.join(workdir, config.INTERNAL.config.install_dir, compo)
185 l_dir_install.append(src.Path(source_dir))
186 l_dir_install.append(src.Path(build_dir))
187 l_dir_install.append(src.Path(install_dir))
192 def product_has_dir(product_info, without_dev=False):
194 Returns a boolean at True if there is a source, build and install
195 directory corresponding to the product described by product_info.
197 :param products_info Config: The config corresponding to the product.
198 :return: True if there is a source, build and install directory corresponding to the product described by product_info.
201 if src.product.product_is_native(product_info) or src.product.product_is_fixed(
206 if src.product.product_is_dev(product_info):
211 def suppress_directories(l_paths, logger):
212 """Suppress the paths given in the list in l_paths.
214 :param l_paths list: The list of Path to be suppressed
215 :param logger Logger: The logger instance to use for the display and logging
220 "Warning: the path %s does not "
221 "exists (or is not a directory)\n" % path.__str__()
223 logger.write(src.printcolors.printcWarning(msg), 1)
225 logger.write(_("Removing %s ...") % path.__str__())
227 logger.write("%s\n" % src.printcolors.printc(src.OK_STATUS), 3)
231 """method called when salomeTools is called with --help option.
233 :return: The text to display for the clean command description.
238 The clean command suppress the SOURCES, BUILD or INSTALL directories of the application products.
239 Use the options to define what directories you want to suppress and to set the list of products
242 >> sat clean SALOME-xx --build --install --properties is_SALOME_module:yes
247 def run(args, runner, logger):
249 method called when salomeTools is called with clean parameter.
253 (options, args) = parser.parse_args(args)
255 # check that the command has been called with an application
256 src.check_config_has_application(runner.cfg)
258 # Get the list of products to threat
259 products_infos = src.product.get_products_list(options, runner.cfg, logger)
261 # Construct the list of directories to suppress
262 l_dir_to_suppress = []
264 l_dir_to_suppress += (
265 get_source_directories(
266 runner.cfg, products_infos, options.sources_without_dev
268 + get_build_directories(products_infos)
269 + get_install_directories(runner.cfg, products_infos)
270 + get_generated_directories(runner.cfg, products_infos)
271 + get_package_directory(runner.cfg)
275 l_dir_to_suppress += get_install_directories(runner.cfg, products_infos)
278 l_dir_to_suppress += get_build_directories(products_infos)
280 if options.sources or options.sources_without_dev:
281 l_dir_to_suppress += get_source_directories(
282 runner.cfg, products_infos, options.sources_without_dev
284 if options.generated:
285 l_dir_to_suppress += get_generated_directories(runner.cfg, products_infos)
288 l_dir_to_suppress += get_package_directory(runner.cfg)
290 if len(l_dir_to_suppress) == 0:
291 logger.write(src.printcolors.printcWarning(_("Nothing to suppress\n")))
295 Please specify what you want to suppress:
296 try 'sat --help clean' and 'sat clean ... --products ... --sources --build --install
302 # Check with the user if he really wants to suppress the directories
303 if not runner.options.batch:
304 logger.write(_("Remove the following directories ?\n"), 1)
305 for directory in l_dir_to_suppress:
306 logger.write(" %s\n" % directory, 1)
307 rep = input(_("Are you sure you want to continue? [Yes/No] "))
308 if rep.upper() != _("YES"):
311 # Suppress the list of paths
312 suppress_directories(l_dir_to_suppress, logger)