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
31 # Define all possible option for the clean command : sat clean <options>
32 parser = src.options.Options()
33 parser.add_option('p', 'products', 'list2', 'products',
34 _('Optional: Products to clean. This option accepts a comma separated list.'))
35 parser.add_option('s', 'sources', 'boolean', 'sources',
36 _("Optional: Clean the product source directories."))
37 parser.add_option('b', 'build', 'boolean', 'build',
38 _("Optional: Clean the product build directories."))
39 parser.add_option('i', 'install', 'boolean', 'install',
40 _("Optional: Clean the product install directories."))
41 parser.add_option('a', 'all', 'boolean', 'all',
42 _("Optional: Clean the product source, build and install directories."))
43 parser.add_option('', 'sources_without_dev', 'boolean', 'sources_without_dev',
44 _("Optional: do not clean the products in development mode."))
47 def get_source_directories(products_infos, without_dev):
49 Returns the list of directory source paths corresponding
50 to the list of product information given as input.
51 If without_dev (bool) the dev products are ignored.
53 :param products_infos list: The list of (name, config) corresponding to one
55 :param without_dev boolean: If True, then ignore the dev products.
56 :return: the list of source paths.
60 for __, product_info in products_infos:
61 if product_has_dir(product_info, without_dev):
62 l_dir_source.append(src.Path(product_info.source_dir))
65 def get_build_directories(products_infos):
67 Returns the list of directory build paths corresponding to the list of
68 product information given as input.
70 :param products_infos list: The list of (name, config) corresponding to one
72 :return: the list of build paths.
76 for __, product_info in products_infos:
77 if product_has_dir(product_info):
78 if "build_dir" in product_info:
79 l_dir_build.append(src.Path(product_info.build_dir))
82 def get_install_directories(products_infos):
84 Returns the list of directory install paths corresponding to the list of
85 product information given as input.
87 :param products_infos list: The list of (name, config) corresponding to one product.
88 :return: the list of install paths.
92 for __, product_info in products_infos:
93 if product_has_dir(product_info):
94 l_dir_install.append(src.Path(product_info.install_dir))
97 def product_has_dir(product_info, without_dev=False):
99 Returns a boolean at True if there is a source, build and install
100 directory corresponding to the product described by product_info.
102 :param products_info Config: The config corresponding to the product.
103 :return: True if there is a source, build and install directory corresponding to the product described by product_info.
106 if (src.product.product_is_native(product_info) or
107 src.product.product_is_fixed(product_info)):
110 if src.product.product_is_dev(product_info):
114 def suppress_directories(l_paths, logger):
115 """Suppress the paths given in the list in l_paths.
117 :param l_paths list: The list of Path to be suppressed
118 :param logger Logger: The logger instance to use for the display and logging
122 msg = _("Warning: the path %s does not "
123 "exists (or is not a directory)\n" % path.__str__())
124 logger.write(src.printcolors.printcWarning(msg), 1)
126 logger.write(_("Removing %s ...") % path.__str__())
128 logger.write('%s\n' % src.printcolors.printc(src.OK_STATUS), 3)
131 """method called when salomeTools is called with --help option.
133 :return: The text to display for the clean command description.
137 The clean command suppress the SOURCES, BUILD or INSTALL directories of the application products.
138 Use the options to define what directories you want to suppress and to set the list of products
141 >> sat clean SALOME-xx --build --install --properties is_salome_module:yes
144 def run(args, runner, logger):
146 method called when salomeTools is called with clean parameter.
150 (options, args) = parser.parse_args(args)
152 # check that the command has been called with an application
153 src.check_config_has_application( runner.cfg )
156 # Get the list of products to threat
157 products_infos = src.product.get_products_list(options, runner.cfg, logger)
159 # Construct the list of directories to suppress
160 l_dir_to_suppress = []
162 l_dir_to_suppress += (get_source_directories(products_infos,
163 options.sources_without_dev) +
164 get_build_directories(products_infos) +
165 get_install_directories(products_infos))
168 l_dir_to_suppress += get_install_directories(products_infos)
171 l_dir_to_suppress += get_build_directories(products_infos)
173 if options.sources or options.sources_without_dev:
174 l_dir_to_suppress += get_source_directories(products_infos,
175 options.sources_without_dev)
177 if len(l_dir_to_suppress) == 0:
178 logger.write(src.printcolors.printcWarning(_("Nothing to suppress\n")))
180 Please specify what you want to suppress:
181 try 'sat --help clean' and 'sat clean ... --products ... --sources --build --install
185 # Check with the user if he really wants to suppress the directories
186 if not runner.options.batch:
187 logger.write(_("Remove the following directories ?\n"), 1)
188 for directory in l_dir_to_suppress:
189 logger.write(" %s\n" % directory, 1)
190 rep = input(_("Are you sure you want to continue? [Yes/No] "))
191 if rep.upper() != _("YES"):
194 # Suppress the list of paths
195 suppress_directories(l_dir_to_suppress, logger)