Salome HOME
sat #8908 : implement verbose option for sat compile
[tools/sat.git] / src / product.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 """\
20 In this file are implemented the methods 
21 relative to the product notion of salomeTools
22 """
23
24 import os
25 import re
26
27 import src
28 import src.debug as DBG
29
30 AVAILABLE_VCS = ['git', 'svn', 'cvs']
31 config_expression = "^config-\d+$"
32 VERSION_DELIMITER = "_to_"
33
34 def get_product_config(config, product_name, with_install_dir=True):
35     """Get the specific configuration of a product from the global configuration
36     
37     :param config Config: The global configuration
38     :param product_name str: The name of the product
39     :param with_install_dir boolean: If false, do not provide an install 
40                                      directory (at false only for internal use 
41                                      of the function check_config_exists)
42     :return: the specific configuration of the product
43     :rtype: Config
44     """
45     
46     # Get the version of the product from the application definition
47     version = config.APPLICATION.products[product_name]
48     # if no version, then take the default one defined in the application
49     if isinstance(version, bool): 
50         version = config.APPLICATION.tag      
51     
52     # Define debug and dev modes
53     # Get the tag if a dictionary is given in APPLICATION.products for the
54     # current product 
55     debug = 'no'
56     dev = 'no'
57     verbose = 'no'
58     base = 'maybe'
59     section = None
60     if isinstance(version, src.pyconf.Mapping):
61         dic_version = version
62         # Get the version/tag
63         if not 'tag' in dic_version:
64             version = config.APPLICATION.tag
65         else:
66             version = dic_version.tag
67         
68         # Get the debug if any
69         if 'debug' in dic_version:
70             debug = dic_version.debug
71         
72         # Get the verbose if any
73         if 'verbose' in dic_version:
74             verbose = dic_version.verbose
75         
76         # Get the dev if any
77         if 'dev' in dic_version:
78             dev = dic_version.dev
79         
80         # Get the base if any
81         if 'base' in dic_version:
82             base = dic_version.base
83
84         # Get the section if any
85         if 'section' in dic_version:
86             section = dic_version.section
87     
88     vv = version
89     # substitute some character with _ in order to get the correct definition
90     # in config.PRODUCTS. This is done because the pyconf tool does not handle
91     # the . and - characters 
92     for c in ".-": vv = vv.replace(c, "_")
93     
94     prod_info = None
95     if product_name in config.PRODUCTS:
96         # Search for the product description in the configuration
97         prod_info = get_product_section(config, product_name, vv, section)
98         
99         # merge opt_depend in depend
100         if prod_info is not None and 'opt_depend' in prod_info:
101             for depend in prod_info.opt_depend:
102                 if depend in config.APPLICATION.products:
103                     prod_info.depend.append(depend,'')
104         
105         # In case of a product get with a vcs, 
106         # put the tag (equal to the version)
107         if prod_info is not None and prod_info.get_source in AVAILABLE_VCS:
108             
109             if prod_info.get_source == 'git':
110                 prod_info.git_info.tag = version
111             
112             if prod_info.get_source == 'svn':
113                 prod_info.svn_info.tag = version
114             
115             if prod_info.get_source == 'cvs':
116                 prod_info.cvs_info.tag = version
117         
118         # In case of a fixed product, 
119         # define the install_dir (equal to the version)
120         if prod_info is not None and os.path.isdir(version):
121             prod_info.install_dir = version
122             prod_info.get_source = "fixed"
123         
124         # Check if the product is defined as native in the application
125         if prod_info is not None:
126             if version == "native":
127                 prod_info.get_source = "native"
128             elif prod_info.get_source == "native":
129                 msg = _("The product %(prod)s has version %(ver)s but is "
130                         "declared as native in its definition" %
131                         { 'prod': prod_info.name, 'ver': version})
132                 raise src.SatException(msg)
133
134     # If there is no definition but the product is declared as native,
135     # construct a new definition containing only the get_source key
136     if prod_info is None and version == "native":
137         prod_info = src.pyconf.Config()
138         prod_info.name = product_name
139         prod_info.get_source = "native"
140
141     # If there is no definition but the product is fixed,
142     # construct a new definition containing only the product name
143     if prod_info is None and os.path.isdir(version):
144         prod_info = src.pyconf.Config()
145         prod_info.name = product_name
146         prod_info.get_source = "fixed"
147         prod_info.addMapping("environ", src.pyconf.Mapping(prod_info), "")
148
149
150     # If prod_info is still None, it means that there is no product definition
151     # in the config. The user has to provide it.
152     if prod_info is None:
153         prod_pyconf_path = src.find_file_in_lpath(product_name + ".pyconf",
154                                                   config.PATHS.PRODUCTPATH)
155         if not prod_pyconf_path:
156             msg = _("""\
157 No definition found for the product %(1)s.
158 Please create a %(2)s.pyconf file somewhere in:
159 %(3)s""") % {
160   "1": product_name, 
161   "2": product_name,
162   "3": config.PATHS.PRODUCTPATH }
163         else:
164             msg = _("""\
165 No definition corresponding to the version %(1)s was found in the file:
166   %(2)s.
167 Please add a section in it.""") % {"1" : vv, "2" : prod_pyconf_path}
168         raise src.SatException(msg)
169     
170     # Set the debug, dev and version keys
171     prod_info.debug = debug
172     prod_info.verbose = verbose
173     prod_info.dev = dev
174     prod_info.version = version
175     
176     # Set the archive_info if the product is get in archive mode
177     if prod_info.get_source == "archive":
178         if not "archive_info" in prod_info:
179             prod_info.addMapping("archive_info",
180                                  src.pyconf.Mapping(prod_info),
181                                  "")
182         if "archive_name" not in prod_info.archive_info: 
183             arch_name = product_name + "-" + version + ".tar.gz"
184             arch_path = src.find_file_in_lpath(arch_name,
185                                                config.PATHS.ARCHIVEPATH)
186             if not arch_path:
187                 msg = _("Archive %(1)s for %(2)s not found in config.PATHS.ARCHIVEPATH") % \
188                        {"1" : arch_name, "2" : prod_info.name}
189                 DBG.tofix(msg, config.PATHS.ARCHIVEPATH)
190                 prod_info.archive_info.archive_name = arch_name #without path
191                 # raise src.SatException(msg) #may be a warning, continue #8646
192             else:
193                 prod_info.archive_info.archive_name = arch_path
194         else:
195             if (os.path.basename(prod_info.archive_info.archive_name) == 
196                                         prod_info.archive_info.archive_name):
197                 arch_name = prod_info.archive_info.archive_name
198                 arch_path = src.find_file_in_lpath(
199                                             arch_name,
200                                             config.PATHS.ARCHIVEPATH)
201                 if not arch_path:
202                     msg = _("Archive %(1)s for %(2)s not found in config.PATHS.ARCHIVEPATH") % \
203                            {"1" : arch_name, "2" : prod_info.name}
204                     DBG.tofix(msg, config.PATHS.ARCHIVEPATH) #avoid 2 messages in compile
205                     prod_info.archive_info.archive_name = arch_name #without path
206                     # raise src.SatException(msg) #may be a warning, continue #8646
207                 else:
208                     prod_info.archive_info.archive_name = arch_path
209
210         
211     # If the product compiles with a script, check the script existence
212     # and if it is executable
213     if product_has_script(prod_info):
214         # Check the compil_script key existence
215         if "compil_script" not in prod_info:
216             msg = _("""\
217 No compilation script found for the product %s.
218 Please provide a 'compil_script' key in its definition.""") % product_name
219             raise src.SatException(msg)
220         
221         # Get the path of the script
222         script = prod_info.compil_script
223         script_name = os.path.basename(script)
224         if script == script_name:
225             # Only a name is given. Search in the default directory
226             script_path = src.find_file_in_lpath(script_name,
227                                                  config.PATHS.PRODUCTPATH,
228                                                  "compil_scripts")
229             if not script_path:
230                 raise src.SatException(
231                     _("Compilation script not found: %s") % script_name)
232             prod_info.compil_script = script_path
233             if src.architecture.is_windows():
234                 prod_info.compil_script = prod_info.compil_script[:-len(".sh")] + ".bat"
235        
236         # Check that the script is executable
237         if not os.access(prod_info.compil_script, os.X_OK):
238             #raise src.SatException(
239             #        _("Compilation script cannot be executed: %s") % 
240             #        prod_info.compil_script)
241             DBG.tofix("Compilation script cannot be executed:", prod_info.compil_script)
242     
243     # Get the full paths of all the patches
244     if product_has_patches(prod_info):
245         patches = []
246         try:
247           for patch in prod_info.patches:
248               patch_path = patch
249               # If only a filename, then search for the patch in the PRODUCTPATH
250               if os.path.basename(patch_path) == patch_path:
251                   # Search in the PRODUCTPATH/patches
252                   patch_path = src.find_file_in_lpath(patch,
253                                                       config.PATHS.PRODUCTPATH,
254                                                       "patches")
255                   if not patch_path:
256                       msg = _("Patch %(patch_name)s for %(prod_name)s not found:"
257                               "\n" % {"patch_name" : patch,
258                                        "prod_name" : prod_info.name}) 
259                       raise src.SatException(msg)
260               patches.append(patch_path)
261         except:
262           DBG.tofix("problem in prod_info.patches", prod_info)
263         prod_info.patches = patches
264
265     # Get the full paths of the environment scripts
266     if product_has_env_script(prod_info):
267         env_script_path = prod_info.environ.env_script
268         # If only a filename, then search for the environment script 
269         # in the PRODUCTPATH/env_scripts
270         if os.path.basename(env_script_path) == env_script_path:
271             # Search in the PRODUCTPATH/env_scripts
272             env_script_path = src.find_file_in_lpath(
273                                             prod_info.environ.env_script,
274                                             config.PATHS.PRODUCTPATH,
275                                             "env_scripts")
276             if not env_script_path:
277                 msg = _("Environment script %(env_name)s for %(prod_name)s not "
278                         "found.\n" % {"env_name" : env_script_path,
279                                        "prod_name" : prod_info.name}) 
280                 raise src.SatException(msg)
281
282         prod_info.environ.env_script = env_script_path
283     
284     if with_install_dir: 
285         # The variable with_install_dir is at false only for internal use 
286         # of the function get_install_dir
287         
288         # Save the install_dir key if there is any
289         if "install_dir" in prod_info and not "install_dir_save" in prod_info:
290             prod_info.install_dir_save = prod_info.install_dir
291         
292         # if it is not the first time the install_dir is computed, it means
293         # that install_dir_save exists and it has to be taken into account.
294         if "install_dir_save" in prod_info:
295             prod_info.install_dir = prod_info.install_dir_save
296         
297         # Set the install_dir key
298         prod_info.install_dir = get_install_dir(config, base, version, prod_info)
299                 
300     return prod_info
301
302 def get_product_section(config, product_name, version, section=None):
303     """Get the product description from the configuration
304     
305     :param config Config: The global configuration
306     :param product_name str: The product name
307     :param version str: The version of the product
308     :param section str: The searched section (if not None, the section is 
309                         explicitly given
310     :return: The product description
311     :rtype: Config
312     """
313
314     # if section is not None, try to get the corresponding section
315     if section:
316         if section not in config.PRODUCTS[product_name]:
317             return None
318         # returns specific information for the given version
319         prod_info = config.PRODUCTS[product_name][section]
320         prod_info.section = section
321         prod_info.from_file = config.PRODUCTS[product_name].from_file
322         return prod_info
323
324     # If it exists, get the information of the product_version
325     if "version_" + version in config.PRODUCTS[product_name]:
326         # returns specific information for the given version
327         prod_info = config.PRODUCTS[product_name]["version_" + version]
328         prod_info.section = "version_" + version
329         prod_info.from_file = config.PRODUCTS[product_name].from_file
330         return prod_info
331     
332     # Else, check if there is a description for multiple versions
333     l_section_name = config.PRODUCTS[product_name].keys()
334     l_section_ranges = [section_name for section_name in l_section_name 
335                         if VERSION_DELIMITER in section_name]
336     for section_range in l_section_ranges:
337         minimum, maximum = section_range.split(VERSION_DELIMITER)
338         if (src.only_numbers(version) >= src.only_numbers(minimum)
339                     and src.only_numbers(version) <= src.only_numbers(maximum)):
340             # returns specific information for the versions
341             prod_info = config.PRODUCTS[product_name][section_range]
342             prod_info.section = section_range
343             prod_info.from_file = config.PRODUCTS[product_name].from_file
344             return prod_info
345     
346     # Else, get the standard informations
347     if "default" in config.PRODUCTS[product_name]:
348         # returns the generic information (given version not found)
349         prod_info = config.PRODUCTS[product_name].default
350         prod_info.section = "default"
351         prod_info.from_file = config.PRODUCTS[product_name].from_file
352         return prod_info
353     
354     # if noting was found, return None
355     return None
356     
357 def get_install_dir(config, base, version, prod_info):
358     """Compute the installation directory of a given product 
359     
360     :param config Config: The global configuration
361     :param base str: This corresponds to the value given by user in its 
362                      application.pyconf for the specific product. If "yes", the
363                      user wants the product to be in base. If "no", he wants the
364                      product to be in the application workdir
365     :param version str: The version of the product
366     :param product_info Config: The configuration specific to 
367                                the product
368     
369     :return: The path of the product installation
370     :rtype: str
371     """
372     install_dir = ""
373     in_base = False
374     if (("install_dir" in prod_info and prod_info.install_dir == "base") 
375                                                             or base == "yes"):
376         in_base = True
377     if (base == "no" or ("no_base" in config.APPLICATION 
378                          and config.APPLICATION.no_base == "yes")):
379         in_base = False
380     
381     if in_base:
382         install_dir = get_base_install_dir(config, prod_info, version)
383     else:
384         if "install_dir" not in prod_info or prod_info.install_dir == "base":
385             # Set it to the default value (in application directory)
386             install_dir = os.path.join(config.APPLICATION.workdir,
387                                                 "INSTALL",
388                                                 prod_info.name)
389         else:
390             install_dir = prod_info.install_dir
391
392     return install_dir
393
394 def get_base_install_dir(config, prod_info, version):
395     """Compute the installation directory of a product in base 
396     
397     :param config Config: The global configuration
398     :param product_info Config: The configuration specific to 
399                                the product
400     :param version str: The version of the product    
401     :return: The path of the product installation
402     :rtype: str
403     """    
404     base_path = src.get_base_path(config) 
405     prod_dir = os.path.join(base_path, prod_info.name + "-" + version)
406     if not os.path.exists(prod_dir):
407         return os.path.join(prod_dir, "config-1")
408     
409     exists, install_dir = check_config_exists(config, prod_dir, prod_info)
410     if exists:
411         return install_dir
412     
413     # Find the first config-<i> directory that is available in the product
414     # directory
415     found = False 
416     label = 1
417     while not found:
418         install_dir = os.path.join(prod_dir, "config-%i" % label)
419         if os.path.exists(install_dir):
420             label+=1
421         else:
422             found = True
423             
424     return install_dir
425
426 def check_config_exists(config, prod_dir, prod_info):
427     """\
428     Verify that the installation directory of a product in a base exists
429     Check all the config-<i> directory and verify the sat-config.pyconf file
430     that is in it 
431     
432     :param config Config: The global configuration
433     :param prod_dir str: The product installation directory path 
434                          (without config-<i>)
435     :param product_info Config: The configuration specific to 
436                                the product
437     :return: True or false is the installation is found or not 
438              and if it is found, the path of the found installation
439     :rtype: (boolean, str)
440     """   
441     # check if the directories or files of the directory corresponds to the 
442     # directory installation of the product
443     l_dir_and_files = os.listdir(prod_dir)
444     for dir_or_file in l_dir_and_files:
445         oExpr = re.compile(config_expression)
446         if not(oExpr.search(dir_or_file)):
447             # not config-<i>, not interesting
448             continue
449         # check if there is the file sat-config.pyconf file in the installation
450         # directory    
451         config_file = os.path.join(prod_dir, dir_or_file, src.CONFIG_FILENAME)
452         if not os.path.exists(config_file):
453             continue
454         
455         # If there is no dependency, it is the right path
456         if len(prod_info.depend)==0:
457             compile_cfg = src.pyconf.Config(config_file)
458             if len(compile_cfg) == 0:
459                 return True, os.path.join(prod_dir, dir_or_file)
460             continue
461         
462         # check if there is the config described in the file corresponds the 
463         # dependencies of the product
464         config_corresponds = True    
465         compile_cfg = src.pyconf.Config(config_file)
466         for prod_dep in prod_info.depend:
467             # if the dependency is not in the config, 
468             # the config does not correspond
469             if prod_dep not in compile_cfg:
470                 config_corresponds = False
471                 break
472             else:
473                 prod_dep_info = get_product_config(config, prod_dep, False)
474                 # If the version of the dependency does not correspond, 
475                 # the config does not correspond
476                 if prod_dep_info.version != compile_cfg[prod_dep]:
477                     config_corresponds = False
478                     break
479         
480         for prod_name in compile_cfg:
481             if prod_name not in prod_info.depend:
482                 config_corresponds = False
483                 break
484         
485         if config_corresponds:
486             return True, os.path.join(prod_dir, dir_or_file)
487     
488     return False, None
489             
490             
491     
492 def get_products_infos(lproducts, config):
493     """Get the specific configuration of a list of products
494     
495     :param lproducts List: The list of product names
496     :param config Config: The global configuration
497     :return: the list of tuples 
498              (product name, specific configuration of the product)
499     :rtype: [(str, Config)]
500     """
501     products_infos = []
502     # Loop on product names
503     for prod in lproducts:       
504         # Get the specific configuration of the product
505         prod_info = get_product_config(config, prod)
506         if prod_info is not None:
507             products_infos.append((prod, prod_info))
508         else:
509             msg = _("The %s product has no definition "
510                     "in the configuration.") % prod
511             raise src.SatException(msg)
512     return products_infos
513
514 def get_product_dependencies(config, product_info):
515     """\
516     Get recursively the list of products that are 
517     in the product_info dependencies
518     
519     :param config Config: The global configuration
520     :param product_info Config: The configuration specific to 
521                                the product
522     :return: the list of products in dependence
523     :rtype: list
524     """
525     if "depend" not in product_info or product_info.depend == []:
526         return []
527     res = []
528     for prod in product_info.depend:
529         if prod == product_info.name:
530             continue
531         if prod not in res:
532             res.append(prod)
533         prod_info = get_product_config(config, prod)
534         dep_prod = get_product_dependencies(config, prod_info)
535         for prod_in_dep in dep_prod:
536             if prod_in_dep not in res:
537                 res.append(prod_in_dep)
538     return res
539
540 def check_installation(product_info):
541     """\
542     Verify if a product is well installed. Checks install directory presence
543     and some additional files if it is defined in the config 
544     
545     :param product_info Config: The configuration specific to 
546                                the product
547     :return: True if it is well installed
548     :rtype: boolean
549     """
550     if not product_compiles(product_info):
551         return True
552     install_dir = product_info.install_dir
553     if not os.path.exists(install_dir):
554         return False
555     if ("present_files" in product_info and 
556         "install" in product_info.present_files):
557         for file_relative_path in product_info.present_files.install:
558             file_path = os.path.join(install_dir, file_relative_path)
559             if not os.path.exists(file_path):
560                 return False
561     return True
562
563 def check_source(product_info):
564     """Verify if a sources of product is preset. Checks source directory presence
565     
566     :param product_info Config: The configuration specific to 
567                                the product
568     :return: True if it is well installed
569     :rtype: boolean
570     """
571     DBG.write("check_source product_info", product_info)
572     source_dir = product_info.source_dir
573     if not os.path.exists(source_dir):
574         return False
575     if ("present_files" in product_info and 
576         "source" in product_info.present_files):
577         for file_relative_path in product_info.present_files.source:
578             file_path = os.path.join(source_dir, file_relative_path)
579             if not os.path.exists(file_path):
580                 return False
581     return True
582
583 def product_is_salome(product_info):
584     """Know if a product is a SALOME module
585     
586     :param product_info Config: The configuration specific to 
587                                the product
588     :return: True if the product is a SALOME module, else False
589     :rtype: boolean
590     """
591     return ("properties" in product_info and
592             "is_SALOME_module" in product_info.properties and
593             product_info.properties.is_SALOME_module == "yes")
594
595 def product_is_fixed(product_info):
596     """Know if a product is fixed
597     
598     :param product_info Config: The configuration specific to 
599                                the product
600     :return: True if the product is fixed, else False
601     :rtype: boolean
602     """
603     get_src = product_info.get_source
604     return get_src.lower() == 'fixed'
605
606 def product_is_native(product_info):
607     """Know if a product is native
608     
609     :param product_info Config: The configuration specific to 
610                                the product
611     :return: True if the product is native, else False
612     :rtype: boolean
613     """
614     get_src = product_info.get_source
615     return get_src.lower() == 'native'
616
617 def product_is_dev(product_info):
618     """Know if a product is in dev mode
619     
620     :param product_info Config: The configuration specific to 
621                                the product
622     :return: True if the product is in dev mode, else False
623     :rtype: boolean
624     """
625     dev = product_info.dev
626     res = (dev.lower() == 'yes')
627     DBG.write('product_is_dev %s' % product_info.name, res)
628     # if product_info.name == "XDATA": return True #test #10569
629     return res
630
631 def product_is_debug(product_info):
632     """Know if a product is in debug mode
633     
634     :param product_info Config: The configuration specific to 
635                                the product
636     :return: True if the product is in debug mode, else False
637     :rtype: boolean
638     """
639     debug = product_info.debug
640     return debug.lower() == 'yes'
641
642 def product_is_verbose(product_info):
643     """Know if a product is in verbose mode
644     
645     :param product_info Config: The configuration specific to 
646                                the product
647     :return: True if the product is in verbose mode, else False
648     :rtype: boolean
649     """
650     verbose = product_info.verbose
651     return verbose.lower() == 'yes'
652
653 def product_is_autotools(product_info):
654     """Know if a product is compiled using the autotools
655     
656     :param product_info Config: The configuration specific to 
657                                the product
658     :return: True if the product is autotools, else False
659     :rtype: boolean
660     """
661     build_src = product_info.build_source
662     return build_src.lower() == 'autotools'
663
664 def product_is_cmake(product_info):
665     """Know if a product is compiled using the cmake
666     
667     :param product_info Config: The configuration specific to 
668                                the product
669     :return: True if the product is cmake, else False
670     :rtype: boolean
671     """
672     build_src = product_info.build_source
673     return build_src.lower() == 'cmake'
674
675 def product_is_vcs(product_info):
676     """Know if a product is download using git, svn or cvs (not archive)
677     
678     :param product_info Config: The configuration specific to 
679                                the product
680     :return: True if the product is vcs, else False
681     :rtype: boolean
682     """
683     return product_info.get_source in AVAILABLE_VCS
684
685 def product_is_smesh_plugin(product_info):
686     """Know if a product is a SMESH plugin
687     
688     :param product_info Config: The configuration specific to 
689                                the product
690     :return: True if the product is a SMESH plugin, else False
691     :rtype: boolean
692     """
693     return ("properties" in product_info and
694             "smesh_plugin" in product_info.properties and
695             product_info.properties.smesh_plugin == "yes")
696
697 def product_is_cpp(product_info):
698     """Know if a product is cpp
699     
700     :param product_info Config: The configuration specific to 
701                                the product
702     :return: True if the product is a cpp, else False
703     :rtype: boolean
704     """
705     return ("properties" in product_info and
706             "cpp" in product_info.properties and
707             product_info.properties.cpp == "yes")
708
709 def product_compiles(product_info):
710     """\
711     Know if a product compiles or not 
712     (some products do not have a compilation procedure)
713     
714     :param product_info Config: The configuration specific to 
715                                the product
716     :return: True if the product compiles, else False
717     :rtype: boolean
718     """
719     return not("properties" in product_info and
720             "compilation" in product_info.properties and
721             product_info.properties.compilation == "no")
722
723 def product_has_script(product_info):
724     """Know if a product has a compilation script
725     
726     :param product_info Config: The configuration specific to 
727                                the product
728     :return: True if the product it has a compilation script, else False
729     :rtype: boolean
730     """
731     if "build_source" not in product_info:
732         # Native case
733         return False
734     build_src = product_info.build_source
735     return build_src.lower() == 'script'
736
737 def product_has_env_script(product_info):
738     """Know if a product has an environment script
739     
740     :param product_info Config: The configuration specific to 
741                                the product
742     :return: True if the product it has an environment script, else False
743     :rtype: boolean
744     """
745     return "environ" in product_info and "env_script" in product_info.environ
746
747 def product_has_patches(product_info):
748     """Know if a product has one or more patches
749     
750     :param product_info Config: The configuration specific to 
751                                the product
752     :return: True if the product has one or more patches
753     :rtype: boolean
754     """   
755     res = ( "patches" in product_info and len(product_info.patches) > 0 )
756     DBG.write('product_has_patches %s' % product_info.name, res)
757     # if product_info.name == "XDATA": return True #test #10569
758     return res
759
760 def product_has_logo(product_info):
761     """Know if a product has a logo (YACSGEN generate)
762     
763     :param product_info Config: The configuration specific to 
764                                the product
765     :return: The path of the logo if the product has a logo, else False
766     :rtype: Str
767     """
768     if ("properties" in product_info and
769             "logo" in product_info.properties):
770         return product_info.properties.logo
771     else:
772         return False
773
774 def product_has_salome_gui(product_info):
775     """Know if a product has a SALOME gui
776     
777     :param product_info Config: The configuration specific to 
778                                the product
779     :return: True if the product has a SALOME gui, else False
780     :rtype: Boolean
781     """
782     return ("properties" in product_info and
783             "has_salome_gui" in product_info.properties and
784             product_info.properties.has_salome_gui == "yes")
785
786 def product_is_mpi(product_info):
787     """Know if a product has openmpi in its dependencies
788     
789     :param product_info Config: The configuration specific to 
790                                the product
791     :return: True if the product has openmpi inits dependencies
792     :rtype: boolean
793     """
794     return "openmpi" in product_info.depend
795
796 def product_is_generated(product_info):
797     """Know if a product is generated (YACSGEN)
798     
799     :param product_info Config: The configuration specific to 
800                                the product
801     :return: True if the product is generated
802     :rtype: boolean
803     """
804     return ("properties" in product_info and
805             "generate" in product_info.properties and
806             product_info.properties.generate == "yes")
807
808 def get_product_components(product_info):
809     """Get the component list to generate with the product
810     
811     :param product_info Config: The configuration specific to 
812                                the product
813     :return: The list of names of the components
814     :rtype: List
815     
816     """
817     if not product_is_generated(product_info):
818         return []
819     
820     compo_list = []
821     if "component_name" in product_info:
822         compo_list = product_info.component_name
823     
824         if isinstance(compo_list, str):
825             compo_list = [ compo_list ]
826
827     return compo_list