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