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 # Define all possible option for the script command : sat script <options>
24 parser = src.options.Options()
25 parser.add_option('p', 'products', 'list2', 'products',
26 _('Optional: products to configure. This option accepts a comma separated list.'))
27 parser.add_option('', 'nb_proc', 'int', 'nb_proc',
28 _("""Optional: The number of processors to use in the script if the make command is used in it.
29 Warning: the script has to be correctly written if you want this option to work.
30 The $MAKE_OPTIONS has to be used."""), 0)
33 def log_step(logger, header, step):
34 logger.write("\r%s%s" % (header, " " * 20), 3)
35 logger.write("\r%s%s" % (header, step), 3)
36 logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
39 def log_res_step(logger, res):
41 logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
44 logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
47 def run_script_all_products(config, products_infos, nb_proc, logger):
48 '''Execute the script in each product build directory.
50 :param config Config: The global configuration
51 :param products_info list: List of
52 (str, Config) => (product_name, product_info)
53 :param nb_proc int: The number of processors to use
54 :param logger Logger: The logger instance to use for the display and logging
55 :return: the number of failing commands.
59 for p_name_info in products_infos:
60 res_prod = run_script_of_product(p_name_info,
68 def run_script_of_product(p_name_info, nb_proc, config, logger):
69 '''Execute the proper configuration command(s)
70 in the product build directory.
72 :param p_name_info tuple: (str, Config) => (product_name, product_info)
73 :param nb_proc int: The number of processors to use
74 :param config Config: The global configuration
75 :param logger Logger: The logger instance to use for the display
77 :return: 1 if it fails, else 0.
81 p_name, p_info = p_name_info
84 logger.write("\n", 4, False)
85 logger.write("################ ", 4)
86 header = _("Running script of %s") % src.printcolors.printcLabel(p_name)
87 header += " %s " % ("." * (20 - len(p_name)))
88 logger.write(header, 3)
89 logger.write("\n", 4, False)
92 # Do nothing if he product is not compilable or has no compilation script
93 if (("properties" in p_info and "compilation" in p_info.properties and
94 p_info.properties.compilation == "no") or
95 (not src.product.product_has_script(p_info))):
96 log_step(logger, header, "ignored")
97 logger.write("\n", 3, False)
100 # Instantiate the class that manages all the construction commands
101 # like cmake, make, make install, make test, environment management, etc...
102 builder = src.compilation.Builder(config, logger, p_info)
104 # Prepare the environment
105 log_step(logger, header, "PREPARE ENV")
106 res_prepare = builder.prepare()
107 log_res_step(logger, res_prepare)
111 script_path_display = src.printcolors.printcLabel(p_info.compil_script)
112 log_step(logger, header, "SCRIPT " + script_path_display)
113 len_end_line += len(script_path_display)
114 res = builder.do_script_build(p_info.compil_script, number_of_proc=nb_proc)
115 log_res_step(logger, res)
119 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
120 logger.write("\r" + header + src.printcolors.printcError("KO"))
121 logger.write("==== %(KO)s in script execution of %(name)s \n" %
122 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
125 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
126 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
127 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
128 logger.write("==== Script execution of %(name)s %(OK)s \n" %
129 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
131 logger.write("\n", 3, False)
136 '''method that is called when salomeTools is called with --help option.
138 :return: The text to display for the script command description.
141 return _("The script command executes the script(s) of the the given "
142 "products in the build directory.\nThis is done only for the "
143 "products that are constructed using a script (build_source "
144 ": \"script\").\nOtherwise, nothing is done."
145 "\n\nexample:\nsat script SALOME-master --products Python,numpy")
147 def run(args, runner, logger):
148 '''method that is called when salomeTools is called with make parameter.
152 (options, args) = parser.parse_args(args)
154 # check that the command has been called with an application
155 src.check_config_has_application( runner.cfg )
157 # Get the list of products to treat
158 products_infos = src.product.get_products_list(options, runner.cfg, logger)
160 # Print some informations
161 logger.write(_('Executing the script in the build '
162 'directories of the application %s\n') %
163 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
165 info = [(_("BUILD directory"),
166 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
167 src.print_info(logger, info)
169 # Call the function that will loop over all the products and execute
170 # the right command(s)
171 if options.nb_proc is None:
173 res = run_script_all_products(runner.cfg,
178 # Print the final state
179 nb_products = len(products_infos)
185 logger.write(_("\nScript: %(status)s "
186 "(%(valid_result)d/%(nb_products)d)\n") % \
187 { 'status': src.printcolors.printc(final_status),
188 'valid_result': nb_products - res,
189 'nb_products': nb_products }, 1)