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