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