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