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