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