Salome HOME
add the --check option to the compile command in order to launch the tests after...
[tools/sat.git] / commands / compile.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
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.
9 #
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.
14 #
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
18
19 import os
20
21 import src
22
23 # Compatibility python 2/3 for input function
24 # input stays input for python 3 and input = raw_input for python 2
25 try: 
26     input = raw_input
27 except NameError: 
28     pass
29
30 # Define all possible option for the compile command :  sat compile <options>
31 parser = src.options.Options()
32 parser.add_option('p', 'products', 'list2', 'products',
33     _('Optional: products to configure. This option can be'
34     ' passed several time to configure several products.'))
35 parser.add_option('', 'with_fathers', 'boolean', 'fathers',
36     _("Optional: build all necessary products to the given product (KERNEL is "
37       "build before building GUI)."), False)
38 parser.add_option('', 'with_children', 'boolean', 'children',
39     _("Optional: build all products using the given product (all SMESH plugins"
40       " are build after SMESH)."), False)
41 parser.add_option('', 'clean_all', 'boolean', 'clean_all',
42     _("Optional: clean BUILD dir and INSTALL dir before building product."),
43     False)
44 parser.add_option('', 'clean_install', 'boolean', 'clean_install',
45     _("Optional: clean INSTALL dir before building product."), False)
46 parser.add_option('', 'make_flags', 'string', 'makeflags',
47     _("Optional: add extra options to the 'make' command."))
48 parser.add_option('', 'show', 'boolean', 'no_compile',
49     _("Optional: DO NOT COMPILE just show if products are installed or not."),
50     False)
51 parser.add_option('', 'stop_first_fail', 'boolean', 'stop_first_fail', _(
52                   "Optional: Stops the command at first product compilation"
53                   " fail."), False)
54 parser.add_option('', 'check', 'boolean', 'check', _(
55                   "Optional: execute the unit tests after compilation"), False)
56
57 def get_products_list(options, cfg, logger):
58     '''method that gives the product list with their informations from 
59        configuration regarding the passed options.
60     
61     :param options Options: The Options instance that stores the commands 
62                             arguments
63     :param cfg Config: The global configuration
64     :param logger Logger: The logger instance to use for the display and 
65                           logging
66     :return: The list of (product name, product_informations).
67     :rtype: List
68     '''
69     # Get the products to be prepared, regarding the options
70     if options.products is None:
71         # No options, get all products sources
72         products = cfg.APPLICATION.products
73     else:
74         # if option --products, check that all products of the command line
75         # are present in the application.
76         products = options.products
77         for p in products:
78             if p not in cfg.APPLICATION.products:
79                 raise src.SatException(_("Product %(product)s "
80                             "not defined in application %(application)s") %
81                         { 'product': p, 'application': cfg.VARS.application} )
82     
83     # Construct the list of tuple containing 
84     # the products name and their definition
85     products_infos = src.product.get_products_infos(products, cfg)
86     
87     products_infos = [pi for pi in products_infos if not(
88                                      src.product.product_is_fixed(pi[1]))]
89     
90     return products_infos
91
92 def get_children(config, p_name_p_info):
93     l_res = []
94     p_name, __ = p_name_p_info
95     # Get all products of the application
96     products = config.APPLICATION.products
97     products_infos = src.product.get_products_infos(products, config)
98     for p_name_potential_child, p_info_potential_child in products_infos:
99         if ("depend" in p_info_potential_child and 
100                 p_name in p_info_potential_child.depend):
101             l_res.append(p_name_potential_child)
102     return l_res
103
104 def get_recursive_children(config, p_name_p_info, without_native_fixed=False):
105     """ Get the recursive list of the product that depend on 
106         the product defined by prod_info
107     
108     :param config Config: The global configuration
109     :param prod_info Config: The specific config of the product
110     :param without_native_fixed boolean: If true, do not include the fixed
111                                          or native products in the result
112     :return: The list of product_informations.
113     :rtype: List
114     """
115     p_name, __ = p_name_p_info
116     # Initialization of the resulting list
117     l_children = []
118     
119     # Get the direct children (not recursive)
120     l_direct_children = get_children(config, p_name_p_info)
121     # Minimal case : no child
122     if l_direct_children == []:
123         return []
124     # Add the children and call the function to get the children of the
125     # children
126     for child_name in l_direct_children:
127         l_children_name = [pn_pi[0] for pn_pi in l_children]
128         if child_name not in l_children_name:
129             if child_name not in config.APPLICATION.products:
130                 msg = _("The product %(child_name)s that is in %(product_nam"
131                         "e)s children is not present in application "
132                         "%(appli_name)s" % {"child_name" : child_name, 
133                                     "product_name" : p_name.name, 
134                                     "appli_name" : config.VARS.application})
135                 raise src.SatException(msg)
136             prod_info_child = src.product.get_product_config(config,
137                                                               child_name)
138             pname_pinfo_child = (prod_info_child.name, prod_info_child)
139             # Do not append the child if it is native or fixed and 
140             # the corresponding parameter is called
141             if without_native_fixed:
142                 if not(src.product.product_is_native(prod_info_child) or 
143                        src.product.product_is_fixed(prod_info_child)):
144                     l_children.append(pname_pinfo_child)
145             else:
146                 l_children.append(pname_pinfo_child)
147             # Get the children of the children
148             l_grand_children = get_recursive_children(config,
149                                 pname_pinfo_child,
150                                 without_native_fixed = without_native_fixed)
151             l_children += l_grand_children
152     return l_children
153
154 def get_recursive_fathers(config, p_name_p_info, without_native_fixed=False):
155     """ Get the recursive list of the dependencies of the product defined by
156         prod_info
157     
158     :param config Config: The global configuration
159     :param prod_info Config: The specific config of the product
160     :param without_native_fixed boolean: If true, do not include the fixed
161                                          or native products in the result
162     :return: The list of product_informations.
163     :rtype: List
164     """
165     p_name, p_info = p_name_p_info
166     # Initialization of the resulting list
167     l_fathers = []
168     # Minimal case : no dependencies
169     if "depend" not in p_info or p_info.depend == []:
170         return []
171     # Add the dependencies and call the function to get the dependencies of the
172     # dependencies
173     for father_name in p_info.depend:
174         l_fathers_name = [pn_pi[0] for pn_pi in l_fathers]
175         if father_name not in l_fathers_name:
176             if father_name not in config.APPLICATION.products:
177                 msg = _("The product %(father_name)s that is in %(product_nam"
178                         "e)s dependencies is not present in application "
179                         "%(appli_name)s" % {"father_name" : father_name, 
180                                     "product_name" : p_name, 
181                                     "appli_name" : config.VARS.application})
182                 raise src.SatException(msg)
183             prod_info_father = src.product.get_product_config(config,
184                                                               father_name)
185             pname_pinfo_father = (prod_info_father.name, prod_info_father)
186             # Do not append the father if it is native or fixed and 
187             # the corresponding parameter is called
188             if without_native_fixed:
189                 if not(src.product.product_is_native(prod_info_father) or 
190                        src.product.product_is_fixed(prod_info_father)):
191                     l_fathers.append(pname_pinfo_father)
192             else:
193                 l_fathers.append(pname_pinfo_father)
194             # Get the dependencies of the dependency
195             l_grand_fathers = get_recursive_fathers(config,
196                                 pname_pinfo_father,
197                                 without_native_fixed = without_native_fixed)
198             for item in l_grand_fathers:
199                 if item not in l_fathers:
200                     l_fathers.append(item)
201     return l_fathers
202
203 def sort_products(config, p_infos):
204     """ Sort the p_infos regarding the dependencies between the products
205     
206     :param config Config: The global configuration
207     :param p_infos list: List of (str, Config) => (product_name, product_info)
208     """
209     l_prod_sorted = src.deepcopy_list(p_infos)
210     for prod in p_infos:
211         l_fathers = get_recursive_fathers(config,
212                                           prod,
213                                           without_native_fixed=True)
214         l_fathers = [father for father in l_fathers if father in p_infos]
215         if l_fathers == []:
216             continue
217         for p_sorted in l_prod_sorted:
218             if p_sorted in l_fathers:
219                 l_fathers.remove(p_sorted)
220             if l_fathers==[]:
221                 l_prod_sorted.remove(prod)
222                 l_prod_sorted.insert(l_prod_sorted.index(p_sorted)+1, prod)
223                 break
224         
225     return l_prod_sorted
226
227 def extend_with_fathers(config, p_infos):
228     p_infos_res = src.deepcopy_list(p_infos)
229     for p_name_p_info in p_infos:
230         fathers = get_recursive_fathers(config,
231                                         p_name_p_info,
232                                         without_native_fixed=True)
233         for p_name_p_info_father in fathers:
234             if p_name_p_info_father not in p_infos_res:
235                 p_infos_res.append(p_name_p_info_father)
236     return p_infos_res
237
238 def extend_with_children(config, p_infos):
239     p_infos_res = src.deepcopy_list(p_infos)
240     for p_name_p_info in p_infos:
241         children = get_recursive_children(config,
242                                         p_name_p_info,
243                                         without_native_fixed=True)
244         for p_name_p_info_child in children:
245             if p_name_p_info_child not in p_infos_res:
246                 p_infos_res.append(p_name_p_info_child)
247     return p_infos_res    
248
249 def check_dependencies(config, p_name_p_info):
250     l_depends_not_installed = []
251     fathers = get_recursive_fathers(config, p_name_p_info, without_native_fixed=True)
252     for p_name_father, p_info_father in fathers:
253         if not(src.product.check_installation(p_info_father)):
254             l_depends_not_installed.append(p_name_father)
255     return l_depends_not_installed
256
257 def log_step(logger, header, step):
258     logger.write("\r%s%s" % (header, " " * 30), 3)
259     logger.write("\r%s%s" % (header, step), 3)
260     logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
261     logger.flush()
262
263 def log_res_step(logger, res):
264     if res == 0:
265         logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
266         logger.flush()
267     else:
268         logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
269         logger.flush()
270
271 def compile_all_products(sat, config, options, products_infos, logger):
272     '''Execute the proper configuration commands 
273        in each product build directory.
274
275     :param config Config: The global configuration
276     :param products_info list: List of 
277                                  (str, Config) => (product_name, product_info)
278     :param logger Logger: The logger instance to use for the display and logging
279     :return: the number of failing commands.
280     :rtype: int
281     '''
282     res = 0
283     for p_name_info in products_infos:
284         
285         p_name, p_info = p_name_info
286         
287         # Logging
288         len_end_line = 30
289         logger.write("\n", 4, False)
290         logger.write("################ ", 4)
291         header = _("Compilation of %s") % src.printcolors.printcLabel(p_name)
292         header += " %s " % ("." * (len_end_line - len(p_name)))
293         logger.write(header, 3)
294         logger.write("\n", 4, False)
295         logger.flush()
296
297         # Do nothing if the product is not compilable
298         if ("properties" in p_info and "compilation" in p_info.properties and 
299                                             p_info.properties.compilation == "no"):
300             log_step(logger, header, "ignored")
301             logger.write("\n", 3, False)
302             continue
303
304         # Do nothing if the product is native
305         if src.product.product_is_native(p_info):
306             log_step(logger, header, "native")
307             logger.write("\n", 3, False)
308             continue
309
310         # Clean the build and the install directories 
311         # if the corresponding options was called
312         if options.clean_all:
313             log_step(logger, header, "CLEAN BUILD AND INSTALL")
314             sat.clean(config.VARS.application + 
315                       " --products " + p_name + 
316                       " --build --install",
317                       batch=True,
318                       verbose=0,
319                       logger_add_link = logger)
320         
321         # Clean the the install directory 
322         # if the corresponding option was called
323         if options.clean_install and not options.clean_all:
324             log_step(logger, header, "CLEAN INSTALL")
325             sat.clean(config.VARS.application + 
326                       " --products " + p_name + 
327                       " --install",
328                       batch=True,
329                       verbose=0,
330                       logger_add_link = logger)
331         
332         # Check if it was already successfully installed
333         if src.product.check_installation(p_info):
334             logger.write(_("Already installed\n"))
335             continue
336         
337         # If the show option was called, do not launch the compilation
338         if options.no_compile:
339             logger.write(_("Not installed\n"))
340             continue
341         
342         # Check if the dependencies are installed
343         l_depends_not_installed = check_dependencies(config, p_name_info)
344         if len(l_depends_not_installed) > 0:
345             log_step(logger, header, "")
346             logger.write(src.printcolors.printcError(
347                     _("ERROR : the following product(s) is(are) mandatory: ")))
348             for prod_name in l_depends_not_installed:
349                 logger.write(src.printcolors.printcError(prod_name + " "))
350             logger.write("\n")
351             continue
352         
353         # Call the function to compile the product
354         res_prod, len_end_line, error_step = compile_product(sat,
355                                                              p_name_info,
356                                                              config,
357                                                              options,
358                                                              logger,
359                                                              header,
360                                                              len_end_line)
361         
362         if res_prod != 0:
363             res += 1
364             
365             if error_step != "CHECK":
366                 # Clean the install directory if there is any
367                 logger.write(_(
368                             "Cleaning the install directory if there is any\n"),
369                              5)
370                 sat.clean(config.VARS.application + 
371                           " --products " + p_name + 
372                           " --install",
373                           batch=True,
374                           verbose=0,
375                           logger_add_link = logger)
376             
377         # Log the result
378         if res_prod > 0:
379             logger.write("\r%s%s" % (header, " " * len_end_line), 3)
380             logger.write("\r" + header + src.printcolors.printcError("KO ") + error_step)
381             logger.write("\n==== %(KO)s in compile of %(name)s \n" %
382                 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
383             if error_step == "CHECK":
384                 logger.write(_("\nINSTALL directory = %s" % 
385                            src.printcolors.printcInfo(p_info.install_dir)), 3)
386             logger.flush()
387         else:
388             logger.write("\r%s%s" % (header, " " * len_end_line), 3)
389             logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
390             logger.write(_("\nINSTALL directory = %s" % 
391                            src.printcolors.printcInfo(p_info.install_dir)), 3)
392             logger.write("\n==== %s \n" % src.printcolors.printcInfo("OK"), 4)
393             logger.write("\n==== Compilation of %(name)s %(OK)s \n" %
394                 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
395             logger.flush()
396         logger.write("\n", 3, False)
397         
398         
399         if res_prod != 0 and options.stop_first_fail:
400             break
401         
402     return res
403
404 def compile_product(sat, p_name_info, config, options, logger, header, len_end):
405     '''Execute the proper configuration command(s) 
406        in the product build directory.
407     
408     :param p_name_info tuple: (str, Config) => (product_name, product_info)
409     :param config Config: The global configuration
410     :param logger Logger: The logger instance to use for the display 
411                           and logging
412     :param header Str: the header to display when logging
413     :param len_end Int: the lenght of the the end of line (used in display)
414     :return: 1 if it fails, else 0.
415     :rtype: int
416     '''
417     
418     p_name, p_info = p_name_info
419           
420     # Get the build procedure from the product configuration.
421     # It can be :
422     # build_sources : autotools -> build_configure, configure, make, make install
423     # build_sources : cmake     -> cmake, make, make install
424     # build_sources : script    -> script executions
425     res = 0
426     if (src.product.product_is_autotools(p_info) or 
427                                           src.product.product_is_cmake(p_info)):
428         res, len_end_line, error_step = compile_product_cmake_autotools(sat,
429                                                                   p_name_info,
430                                                                   config,
431                                                                   options,
432                                                                   logger,
433                                                                   header,
434                                                                   len_end)
435     if src.product.product_has_script(p_info):
436         res, len_end_line, error_step = compile_product_script(sat,
437                                                                   p_name_info,
438                                                                   config,
439                                                                   options,
440                                                                   logger,
441                                                                   header,
442                                                                   len_end)
443
444     # Check that the install directory exists
445     if res==0 and not(os.path.exists(p_info.install_dir)):
446         res = 1
447         error_step = "NO INSTALL DIR"
448         msg = _("Error: despite the fact that all the steps ended successfully,"
449                 " no install directory was found !")
450         logger.write(src.printcolors.printcError(msg), 4)
451         logger.write("\n", 4)
452         return res, len_end_line, error_step
453     
454     # Add the config file corresponding to the dependencies/versions of the 
455     # product that have been successfully compiled
456     if res==0:       
457         logger.write(_("Add the config file in installation directory\n"), 5)
458         add_compile_config_file(p_info, config)
459         
460         if options.check:
461             # Do the unit tests (call the check command)
462             log_step(logger, header, "CHECK")
463             res_check = sat.check(
464                               config.VARS.application + " --products " + p_name,
465                               verbose = 0,
466                               logger_add_link = logger)
467             if res_check != 0:
468                 error_step = "CHECK"
469                 
470             res += res_check
471     
472     return res, len_end_line, error_step
473
474 def compile_product_cmake_autotools(sat,
475                                     p_name_info,
476                                     config,
477                                     options,
478                                     logger,
479                                     header,
480                                     len_end):
481     '''Execute the proper build procedure for autotools or cmake
482        in the product build directory.
483     
484     :param p_name_info tuple: (str, Config) => (product_name, product_info)
485     :param config Config: The global configuration
486     :param logger Logger: The logger instance to use for the display 
487                           and logging
488     :param header Str: the header to display when logging
489     :param len_end Int: the lenght of the the end of line (used in display)
490     :return: 1 if it fails, else 0.
491     :rtype: int
492     '''
493     p_name, p_info = p_name_info
494     
495     # Execute "sat configure", "sat make" and "sat install"
496     res = 0
497     error_step = ""
498     
499     # Logging and sat command call for configure step
500     len_end_line = len_end
501     log_step(logger, header, "CONFIGURE")
502     res_c = sat.configure(config.VARS.application + " --products " + p_name,
503                           verbose = 0,
504                           logger_add_link = logger)
505     log_res_step(logger, res_c)
506     res += res_c
507     
508     if res_c > 0:
509         error_step = "CONFIGURE"
510     else:
511         # Logging and sat command call for make step
512         # Logging take account of the fact that the product has a compilation 
513         # script or not
514         if src.product.product_has_script(p_info):
515             # if the product has a compilation script, 
516             # it is executed during make step
517             scrit_path_display = src.printcolors.printcLabel(
518                                                         p_info.compil_script)
519             log_step(logger, header, "SCRIPT " + scrit_path_display)
520             len_end_line = len(scrit_path_display)
521         else:
522             log_step(logger, header, "MAKE")
523         make_arguments = config.VARS.application + " --products " + p_name
524         # Get the make_flags option if there is any
525         if options.makeflags:
526             make_arguments += " --option -j" + options.makeflags
527         res_m = sat.make(make_arguments,
528                          verbose = 0,
529                          logger_add_link = logger)
530         log_res_step(logger, res_m)
531         res += res_m
532         
533         if res_m > 0:
534             error_step = "MAKE"
535         else: 
536             # Logging and sat command call for make install step
537             log_step(logger, header, "MAKE INSTALL")
538             res_mi = sat.makeinstall(config.VARS.application + 
539                                      " --products " + 
540                                      p_name,
541                                     verbose = 0,
542                                     logger_add_link = logger)
543
544             log_res_step(logger, res_mi)
545             res += res_mi
546             
547             if res_mi > 0:
548                 error_step = "MAKE INSTALL"
549                 
550     return res, len_end_line, error_step 
551
552 def compile_product_script(sat,
553                            p_name_info,
554                            config,
555                            options,
556                            logger,
557                            header,
558                            len_end):
559     '''Execute the script build procedure in the product build directory.
560     
561     :param p_name_info tuple: (str, Config) => (product_name, product_info)
562     :param config Config: The global configuration
563     :param logger Logger: The logger instance to use for the display 
564                           and logging
565     :param header Str: the header to display when logging
566     :param len_end Int: the lenght of the the end of line (used in display)
567     :return: 1 if it fails, else 0.
568     :rtype: int
569     '''
570     p_name, p_info = p_name_info
571     
572     # Execute "sat configure", "sat make" and "sat install"
573     error_step = ""
574     
575     # Logging and sat command call for the script step
576     scrit_path_display = src.printcolors.printcLabel(p_info.compil_script)
577     log_step(logger, header, "SCRIPT " + scrit_path_display)
578     len_end_line = len_end + len(scrit_path_display)
579     res = sat.script(config.VARS.application + " --products " + p_name,
580                      verbose = 0,
581                      logger_add_link = logger)
582     log_res_step(logger, res)
583               
584     return res, len_end_line, error_step 
585
586 def add_compile_config_file(p_info, config):
587     '''Execute the proper configuration command(s) 
588        in the product build directory.
589     
590     :param p_info Config: The specific config of the product
591     :param config Config: The global configuration
592     '''
593     # Create the compile config
594     compile_cfg = src.pyconf.Config()
595     for prod_name in p_info.depend:
596         if prod_name not in compile_cfg:
597             compile_cfg.addMapping(prod_name,
598                                    src.pyconf.Mapping(compile_cfg),
599                                    "")
600         prod_dep_info = src.product.get_product_config(config, prod_name, False)
601         compile_cfg[prod_name] = prod_dep_info.version
602     # Write it in the install directory of the product
603     compile_cfg_path = os.path.join(p_info.install_dir, src.CONFIG_FILENAME)
604     f = open(compile_cfg_path, 'w')
605     compile_cfg.__save__(f)
606     f.close()
607     
608 def description():
609     '''method that is called when salomeTools is called with --help option.
610     
611     :return: The text to display for the compile command description.
612     :rtype: str
613     '''
614     return _("The compile command constructs the products of the application"
615              "\n\nexample:\nsat compile SALOME-master --products KERNEL,GUI,"
616              "MEDCOUPLING --clean_all")
617   
618 def run(args, runner, logger):
619     '''method that is called when salomeTools is called with compile parameter.
620     '''
621     
622     # Parse the options
623     (options, args) = parser.parse_args(args)
624
625     # Warn the user if he invoked the clean_all option 
626     # without --products option
627     if (options.clean_all and 
628         options.products is None and 
629         not runner.options.batch):
630         rep = input(_("You used --clean_all without specifying a product"
631                           " are you sure you want to continue? [Yes/No] "))
632         if rep.upper() != _("YES").upper():
633             return 0
634         
635     # check that the command has been called with an application
636     src.check_config_has_application( runner.cfg )
637
638     # Print some informations
639     logger.write(_('Executing the compile commands in the build '
640                                 'directories of the products of '
641                                 'the application %s\n') % 
642                 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
643     
644     info = [
645             (_("SOURCE directory"),
646              os.path.join(runner.cfg.APPLICATION.workdir, 'SOURCES')),
647             (_("BUILD directory"),
648              os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))
649             ]
650     src.print_info(logger, info)
651
652     # Get the list of products to treat
653     products_infos = get_products_list(options, runner.cfg, logger)
654
655     if options.fathers:
656         # Extend the list with all recursive dependencies of the given products
657         products_infos = extend_with_fathers(runner.cfg, products_infos)
658
659     if options.children:
660         # Extend the list with all products that use the given products
661         products_infos = extend_with_children(runner.cfg, products_infos)
662
663     # Sort the list regarding the dependencies of the products
664     products_infos = sort_products(runner.cfg, products_infos)
665
666     
667     # Call the function that will loop over all the products and execute
668     # the right command(s)
669     res = compile_all_products(runner, runner.cfg, options, products_infos, logger)
670     
671     # Print the final state
672     nb_products = len(products_infos)
673     if res == 0:
674         final_status = "OK"
675     else:
676         final_status = "KO"
677    
678     logger.write(_("\nCompilation: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
679         { 'status': src.printcolors.printc(final_status), 
680           'valid_result': nb_products - res,
681           'nb_products': nb_products }, 1)    
682     
683     code = res
684     if code != 0:
685         code = 1
686     return code