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