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