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