Salome HOME
spns #8471 : add Windows case to launch tests with the command 'sat test'
[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 file
222         # if windows supposed '.bat', if linux supposed '.sh'
223         # but user set extension script file in his pyconf as he wants, no obligation.
224         script = prod_info.compil_script
225         script_name = os.path.basename(script)
226         if script == script_name:
227             # Only a name is given. Search in the default directory
228             script_path = src.find_file_in_lpath(script_name, config.PATHS.PRODUCTPATH, "compil_scripts")
229             if not script_path:
230                 msg = _("Compilation script not found: %s") % script_name
231                 DBG.tofix(msg, config.PATHS.PRODUCTPATH, True) # say where searched
232                 raise src.SatException(msg)
233             prod_info.compil_script = script_path
234
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             # just as warning, problem later...
242             DBG.tofix("Compilation script is not execute mode file", prod_info.compil_script, True)
243     
244     # Get the full paths of all the patches
245     if product_has_patches(prod_info):
246         patches = []
247         try:
248           for patch in prod_info.patches:
249               patch_path = patch
250               # If only a filename, then search for the patch in the PRODUCTPATH
251               if os.path.basename(patch_path) == patch_path:
252                   # Search in the PRODUCTPATH/patches
253                   patch_path = src.find_file_in_lpath(patch,
254                                                       config.PATHS.PRODUCTPATH,
255                                                       "patches")
256                   if not patch_path:
257                       msg = _("Patch %(patch_name)s for %(prod_name)s not found:"
258                               "\n" % {"patch_name" : patch,
259                                        "prod_name" : prod_info.name}) 
260                       raise src.SatException(msg)
261               patches.append(patch_path)
262         except:
263           DBG.tofix("problem in prod_info.patches", prod_info)
264         prod_info.patches = patches
265
266     # Get the full paths of the environment scripts
267     if product_has_env_script(prod_info):
268         env_script_path = prod_info.environ.env_script
269         # If only a filename, then search for the environment script 
270         # in the PRODUCTPATH/env_scripts
271         if os.path.basename(env_script_path) == env_script_path:
272             # Search in the PRODUCTPATH/env_scripts
273             env_script_path = src.find_file_in_lpath(
274                                             prod_info.environ.env_script,
275                                             config.PATHS.PRODUCTPATH,
276                                             "env_scripts")
277             if not env_script_path:
278                 msg = _("Environment script %(env_name)s for %(prod_name)s not "
279                         "found.\n" % {"env_name" : env_script_path,
280                                        "prod_name" : prod_info.name}) 
281                 raise src.SatException(msg)
282
283         prod_info.environ.env_script = env_script_path
284     
285     if with_install_dir: 
286         # The variable with_install_dir is at false only for internal use 
287         # of the function get_install_dir
288         
289         # Save the install_dir key if there is any
290         if "install_dir" in prod_info and not "install_dir_save" in prod_info:
291             prod_info.install_dir_save = prod_info.install_dir
292         
293         # if it is not the first time the install_dir is computed, it means
294         # that install_dir_save exists and it has to be taken into account.
295         if "install_dir_save" in prod_info:
296             prod_info.install_dir = prod_info.install_dir_save
297         
298         # Set the install_dir key
299         prod_info.install_dir = get_install_dir(config, base, version, prod_info)
300                 
301     return prod_info
302
303 def get_product_section(config, product_name, version, section=None):
304     """Get the product description from the configuration
305     
306     :param config Config: The global configuration
307     :param product_name str: The product name
308     :param version str: The version of the product
309     :param section str: The searched section (if not None, the section is 
310                         explicitly given
311     :return: The product description
312     :rtype: Config
313     """
314
315     # if section is not None, try to get the corresponding section
316     if section:
317         if section not in config.PRODUCTS[product_name]:
318             return None
319         # returns specific information for the given version
320         prod_info = config.PRODUCTS[product_name][section]
321         prod_info.section = section
322         prod_info.from_file = config.PRODUCTS[product_name].from_file
323         return prod_info
324
325     # If it exists, get the information of the product_version
326     if "version_" + version in config.PRODUCTS[product_name]:
327         # returns specific information for the given version
328         prod_info = config.PRODUCTS[product_name]["version_" + version]
329         prod_info.section = "version_" + version
330         prod_info.from_file = config.PRODUCTS[product_name].from_file
331         return prod_info
332     
333     # Else, check if there is a description for multiple versions
334     l_section_name = config.PRODUCTS[product_name].keys()
335     l_section_ranges = [section_name for section_name in l_section_name 
336                         if VERSION_DELIMITER in section_name]
337     for section_range in l_section_ranges:
338         minimum, maximum = section_range.split(VERSION_DELIMITER)
339         if (src.only_numbers(version) >= src.only_numbers(minimum)
340                     and src.only_numbers(version) <= src.only_numbers(maximum)):
341             # returns specific information for the versions
342             prod_info = config.PRODUCTS[product_name][section_range]
343             prod_info.section = section_range
344             prod_info.from_file = config.PRODUCTS[product_name].from_file
345             return prod_info
346     
347     # Else, get the standard informations
348     if "default" in config.PRODUCTS[product_name]:
349         # returns the generic information (given version not found)
350         prod_info = config.PRODUCTS[product_name].default
351         prod_info.section = "default"
352         prod_info.from_file = config.PRODUCTS[product_name].from_file
353         return prod_info
354     
355     # if noting was found, return None
356     return None
357     
358 def get_install_dir(config, base, version, prod_info):
359     """Compute the installation directory of a given product 
360     
361     :param config Config: The global configuration
362     :param base str: This corresponds to the value given by user in its 
363                      application.pyconf for the specific product. If "yes", the
364                      user wants the product to be in base. If "no", he wants the
365                      product to be in the application workdir
366     :param version str: The version of the product
367     :param product_info Config: The configuration specific to 
368                                the product
369     
370     :return: The path of the product installation
371     :rtype: str
372     """
373     install_dir = ""
374     in_base = False
375     if (("install_dir" in prod_info and prod_info.install_dir == "base") 
376                                                             or base == "yes"):
377         in_base = True
378     if (base == "no" or ("no_base" in config.APPLICATION 
379                          and config.APPLICATION.no_base == "yes")):
380         in_base = False
381     
382     if in_base:
383         install_dir = get_base_install_dir(config, prod_info, version)
384     else:
385         if "install_dir" not in prod_info or prod_info.install_dir == "base":
386             # Set it to the default value (in application directory)
387             install_dir = os.path.join(config.APPLICATION.workdir,
388                                                 "INSTALL",
389                                                 prod_info.name)
390         else:
391             install_dir = prod_info.install_dir
392
393     return install_dir
394
395 def get_base_install_dir(config, prod_info, version):
396     """Compute the installation directory of a product in base 
397     
398     :param config Config: The global configuration
399     :param product_info Config: The configuration specific to 
400                                the product
401     :param version str: The version of the product    
402     :return: The path of the product installation
403     :rtype: str
404     """    
405     base_path = src.get_base_path(config) 
406     prod_dir = os.path.join(base_path, prod_info.name + "-" + version)
407     if not os.path.exists(prod_dir):
408         return os.path.join(prod_dir, "config-1")
409     
410     exists, install_dir = check_config_exists(config, prod_dir, prod_info)
411     if exists:
412         return install_dir
413     
414     # Find the first config-<i> directory that is available in the product
415     # directory
416     found = False 
417     label = 1
418     while not found:
419         install_dir = os.path.join(prod_dir, "config-%i" % label)
420         if os.path.exists(install_dir):
421             label+=1
422         else:
423             found = True
424             
425     return install_dir
426
427 def check_config_exists(config, prod_dir, prod_info):
428     """\
429     Verify that the installation directory of a product in a base exists
430     Check all the config-<i> directory and verify the sat-config.pyconf file
431     that is in it 
432     
433     :param config Config: The global configuration
434     :param prod_dir str: The product installation directory path 
435                          (without config-<i>)
436     :param product_info Config: The configuration specific to 
437                                the product
438     :return: True or false is the installation is found or not 
439              and if it is found, the path of the found installation
440     :rtype: (boolean, str)
441     """   
442     # check if the directories or files of the directory corresponds to the 
443     # directory installation of the product
444     l_dir_and_files = os.listdir(prod_dir)
445     for dir_or_file in l_dir_and_files:
446         oExpr = re.compile(config_expression)
447         if not(oExpr.search(dir_or_file)):
448             # not config-<i>, not interesting
449             continue
450         # check if there is the file sat-config.pyconf file in the installation
451         # directory    
452         config_file = os.path.join(prod_dir, dir_or_file, src.CONFIG_FILENAME)
453         if not os.path.exists(config_file):
454             continue
455         
456         # If there is no dependency, it is the right path
457         if len(prod_info.depend)==0:
458             compile_cfg = src.pyconf.Config(config_file)
459             if len(compile_cfg) == 0:
460                 return True, os.path.join(prod_dir, dir_or_file)
461             continue
462         
463         # check if there is the config described in the file corresponds the 
464         # dependencies of the product
465         config_corresponds = True    
466         compile_cfg = src.pyconf.Config(config_file)
467         for prod_dep in prod_info.depend:
468             # if the dependency is not in the config, 
469             # the config does not correspond
470             if prod_dep not in compile_cfg:
471                 config_corresponds = False
472                 break
473             else:
474                 prod_dep_info = get_product_config(config, prod_dep, False)
475                 # If the version of the dependency does not correspond, 
476                 # the config does not correspond
477                 if prod_dep_info.version != compile_cfg[prod_dep]:
478                     config_corresponds = False
479                     break
480         
481         for prod_name in compile_cfg:
482             if prod_name not in prod_info.depend:
483                 config_corresponds = False
484                 break
485         
486         if config_corresponds:
487             return True, os.path.join(prod_dir, dir_or_file)
488     
489     return False, None
490             
491             
492     
493 def get_products_infos(lproducts, config):
494     """Get the specific configuration of a list of products
495     
496     :param lproducts List: The list of product names
497     :param config Config: The global configuration
498     :return: the list of tuples 
499              (product name, specific configuration of the product)
500     :rtype: [(str, Config)]
501     """
502     products_infos = []
503     # Loop on product names
504     for prod in lproducts:       
505         # Get the specific configuration of the product
506         prod_info = get_product_config(config, prod)
507         if prod_info is not None:
508             products_infos.append((prod, prod_info))
509         else:
510             msg = _("The %s product has no definition "
511                     "in the configuration.") % prod
512             raise src.SatException(msg)
513     return products_infos
514
515 def get_product_dependencies(config, product_info):
516     """\
517     Get recursively the list of products that are 
518     in the product_info dependencies
519     
520     :param config Config: The global configuration
521     :param product_info Config: The configuration specific to 
522                                the product
523     :return: the list of products in dependence
524     :rtype: list
525     """
526     if "depend" not in product_info or product_info.depend == []:
527         return []
528     res = []
529     for prod in product_info.depend:
530         if prod == product_info.name:
531             continue
532         if prod not in res:
533             res.append(prod)
534         prod_info = get_product_config(config, prod)
535         dep_prod = get_product_dependencies(config, prod_info)
536         for prod_in_dep in dep_prod:
537             if prod_in_dep not in res:
538                 res.append(prod_in_dep)
539     return res
540
541 def check_installation(product_info):
542     """\
543     Verify if a product is well installed. Checks install directory presence
544     and some additional files if it is defined in the config 
545     
546     :param product_info Config: The configuration specific to 
547                                the product
548     :return: True if it is well installed
549     :rtype: boolean
550     """
551     if not product_compiles(product_info):
552         return True
553     install_dir = product_info.install_dir
554     if not os.path.exists(install_dir):
555         return False
556     if ("present_files" in product_info and 
557         "install" in product_info.present_files):
558         for file_relative_path in product_info.present_files.install:
559             file_path = os.path.join(install_dir, file_relative_path)
560             if not os.path.exists(file_path):
561                 return False
562     return True
563
564 def check_source(product_info):
565     """Verify if a sources of product is preset. Checks source directory presence
566     
567     :param product_info Config: The configuration specific to 
568                                the product
569     :return: True if it is well installed
570     :rtype: boolean
571     """
572     DBG.write("check_source product_info", product_info)
573     source_dir = product_info.source_dir
574     if not os.path.exists(source_dir):
575         return False
576     if ("present_files" in product_info and 
577         "source" in product_info.present_files):
578         for file_relative_path in product_info.present_files.source:
579             file_path = os.path.join(source_dir, file_relative_path)
580             if not os.path.exists(file_path):
581                 return False
582     return True
583
584 def product_is_salome(product_info):
585     """Know if a product is a SALOME module
586     
587     :param product_info Config: The configuration specific to 
588                                the product
589     :return: True if the product is a SALOME module, else False
590     :rtype: boolean
591     """
592     return ("properties" in product_info and
593             "is_SALOME_module" in product_info.properties and
594             product_info.properties.is_SALOME_module == "yes")
595
596 def product_is_fixed(product_info):
597     """Know if a product is fixed
598     
599     :param product_info Config: The configuration specific to 
600                                the product
601     :return: True if the product is fixed, else False
602     :rtype: boolean
603     """
604     get_src = product_info.get_source
605     return get_src.lower() == 'fixed'
606
607 def product_is_native(product_info):
608     """Know if a product is native
609     
610     :param product_info Config: The configuration specific to 
611                                the product
612     :return: True if the product is native, else False
613     :rtype: boolean
614     """
615     get_src = product_info.get_source
616     return get_src.lower() == 'native'
617
618 def product_is_dev(product_info):
619     """Know if a product is in dev mode
620     
621     :param product_info Config: The configuration specific to 
622                                the product
623     :return: True if the product is in dev mode, else False
624     :rtype: boolean
625     """
626     dev = product_info.dev
627     res = (dev.lower() == 'yes')
628     DBG.write('product_is_dev %s' % product_info.name, res)
629     # if product_info.name == "XDATA": return True #test #10569
630     return res
631
632 def product_is_debug(product_info):
633     """Know if a product is in debug mode
634     
635     :param product_info Config: The configuration specific to 
636                                the product
637     :return: True if the product is in debug mode, else False
638     :rtype: boolean
639     """
640     debug = product_info.debug
641     return debug.lower() == 'yes'
642
643 def product_is_verbose(product_info):
644     """Know if a product is in verbose mode
645     
646     :param product_info Config: The configuration specific to 
647                                the product
648     :return: True if the product is in verbose mode, else False
649     :rtype: boolean
650     """
651     verbose = product_info.verbose
652     return verbose.lower() == 'yes'
653
654 def product_is_autotools(product_info):
655     """Know if a product is compiled using the autotools
656     
657     :param product_info Config: The configuration specific to 
658                                the product
659     :return: True if the product is autotools, else False
660     :rtype: boolean
661     """
662     build_src = product_info.build_source
663     return build_src.lower() == 'autotools'
664
665 def product_is_cmake(product_info):
666     """Know if a product is compiled using the cmake
667     
668     :param product_info Config: The configuration specific to 
669                                the product
670     :return: True if the product is cmake, else False
671     :rtype: boolean
672     """
673     build_src = product_info.build_source
674     return build_src.lower() == 'cmake'
675
676 def product_is_vcs(product_info):
677     """Know if a product is download using git, svn or cvs (not archive)
678     
679     :param product_info Config: The configuration specific to 
680                                the product
681     :return: True if the product is vcs, else False
682     :rtype: boolean
683     """
684     return product_info.get_source in AVAILABLE_VCS
685
686 def product_is_smesh_plugin(product_info):
687     """Know if a product is a SMESH plugin
688     
689     :param product_info Config: The configuration specific to 
690                                the product
691     :return: True if the product is a SMESH plugin, else False
692     :rtype: boolean
693     """
694     return ("properties" in product_info and
695             "smesh_plugin" in product_info.properties and
696             product_info.properties.smesh_plugin == "yes")
697
698 def product_is_cpp(product_info):
699     """Know if a product is cpp
700     
701     :param product_info Config: The configuration specific to 
702                                the product
703     :return: True if the product is a cpp, else False
704     :rtype: boolean
705     """
706     return ("properties" in product_info and
707             "cpp" in product_info.properties and
708             product_info.properties.cpp == "yes")
709
710 def product_compiles(product_info):
711     """\
712     Know if a product compiles or not 
713     (some products do not have a compilation procedure)
714     
715     :param product_info Config: The configuration specific to 
716                                the product
717     :return: True if the product compiles, else False
718     :rtype: boolean
719     """
720     return not("properties" in product_info and
721             "compilation" in product_info.properties and
722             product_info.properties.compilation == "no")
723
724 def product_has_script(product_info):
725     """Know if a product has a compilation script
726     
727     :param product_info Config: The configuration specific to 
728                                the product
729     :return: True if the product it has a compilation script, else False
730     :rtype: boolean
731     """
732     if "build_source" not in product_info:
733         # Native case
734         return False
735     build_src = product_info.build_source
736     return build_src.lower() == 'script'
737
738 def product_has_env_script(product_info):
739     """Know if a product has an environment script
740     
741     :param product_info Config: The configuration specific to 
742                                the product
743     :return: True if the product it has an environment script, else False
744     :rtype: boolean
745     """
746     return "environ" in product_info and "env_script" in product_info.environ
747
748 def product_has_patches(product_info):
749     """Know if a product has one or more patches
750     
751     :param product_info Config: The configuration specific to 
752                                the product
753     :return: True if the product has one or more patches
754     :rtype: boolean
755     """   
756     res = ( "patches" in product_info and len(product_info.patches) > 0 )
757     DBG.write('product_has_patches %s' % product_info.name, res)
758     # if product_info.name == "XDATA": return True #test #10569
759     return res
760
761 def product_has_logo(product_info):
762     """Know if a product has a logo (YACSGEN generate)
763     
764     :param product_info Config: The configuration specific to 
765                                the product
766     :return: The path of the logo if the product has a logo, else False
767     :rtype: Str
768     """
769     if ("properties" in product_info and
770             "logo" in product_info.properties):
771         return product_info.properties.logo
772     else:
773         return False
774
775 def product_has_salome_gui(product_info):
776     """Know if a product has a SALOME gui
777     
778     :param product_info Config: The configuration specific to 
779                                the product
780     :return: True if the product has a SALOME gui, else False
781     :rtype: Boolean
782     """
783     return ("properties" in product_info and
784             "has_salome_gui" in product_info.properties and
785             product_info.properties.has_salome_gui == "yes")
786
787 def product_is_mpi(product_info):
788     """Know if a product has openmpi in its dependencies
789     
790     :param product_info Config: The configuration specific to 
791                                the product
792     :return: True if the product has openmpi inits dependencies
793     :rtype: boolean
794     """
795     return "openmpi" in product_info.depend
796
797 def product_is_generated(product_info):
798     """Know if a product is generated (YACSGEN)
799     
800     :param product_info Config: The configuration specific to 
801                                the product
802     :return: True if the product is generated
803     :rtype: boolean
804     """
805     return ("properties" in product_info and
806             "generate" in product_info.properties and
807             product_info.properties.generate == "yes")
808
809 def get_product_components(product_info):
810     """Get the component list to generate with the product
811     
812     :param product_info Config: The configuration specific to 
813                                the product
814     :return: The list of names of the components
815     :rtype: List
816     
817     """
818     if not product_is_generated(product_info):
819         return []
820     
821     compo_list = []
822     if "component_name" in product_info:
823         compo_list = product_info.component_name
824     
825         if isinstance(compo_list, str):
826             compo_list = [ compo_list ]
827
828     return compo_list