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