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