3 # Copyright (C) 2010-2012 CEA/DEN
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.
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.
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
20 In this file are implemented the methods
21 relative to the product notion of salomeTools
29 import src.debug as DBG
30 import src.versionMinorMajorPatch as VMMP
32 AVAILABLE_VCS = ['git', 'svn', 'cvs']
34 CONFIG_FILENAME = "sat-config-" # trace product depends version(s)
35 PRODUCT_FILENAME = "sat-product-" # trace product compile config
36 config_expression = "^config-\d+$"
38 def get_product_config(config, product_name, with_install_dir=True):
39 """Get the specific configuration of a product from the global configuration
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
50 # Get the version of the product from the application definition
51 version = config.APPLICATION.products[product_name]
53 # Define debug and dev modes
54 # Get the tag if a dictionary is given in APPLICATION.products for the
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
77 # special case for which only the product name is mentionned
78 if isinstance(version, bool):
79 version = config.APPLICATION.tag
81 if isinstance(version, src.pyconf.Mapping):
84 if not 'tag' in dic_version:
85 version = config.APPLICATION.tag
87 version = dic_version.tag
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
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
102 if 'dev' in dic_version:
103 dev = dic_version.dev
104 elif 'dev' in config.APPLICATION:
105 dev = config.APPLICATION.dev
108 if 'hpc' in dic_version:
109 hpc = dic_version.hpc
110 elif 'hpc' in config.APPLICATION:
111 hpc = config.APPLICATION.hpc
113 # Get the base if any
114 if 'base' in dic_version:
115 base = dic_version.base
116 elif 'base' in config.APPLICATION:
117 base = config.APPLICATION.base
119 # Get the section if any
120 if 'section' in dic_version:
121 section = dic_version.section
123 # this case occur when version is overwritten, cf sat # 8897
124 if isinstance(version, dict):
125 dic_version = version
126 # Get the version/tag
127 if not 'tag' in dic_version:
128 version = config.APPLICATION.tag
130 version = dic_version["tag"]
132 # Get the debug if any
133 if 'debug' in dic_version:
134 debug = dic_version["debug"]
135 elif 'debug' in config.APPLICATION:
136 debug = config.APPLICATION.debug
138 # Get the verbose if any
139 if 'verbose' in dic_version:
140 verbose = dic_version["verbose"]
141 elif 'verbose' in config.APPLICATION:
142 verbose = config.APPLICATION.verbose
145 if 'dev' in dic_version:
146 dev = dic_version["dev"]
147 elif 'dev' in config.APPLICATION:
148 dev = config.APPLICATION.dev
151 if 'hpc' in dic_version:
152 hpc = dic_version.hpc
153 elif 'hpc' in config.APPLICATION:
154 hpc = config.APPLICATION.hpc
156 # Get the base if any
157 if 'base' in dic_version:
158 base = dic_version["base"]
160 # Get the section if any
161 if 'section' in dic_version:
162 section = dic_version['section']
165 # substitute some character with _ in order to get the correct definition
166 # in config.PRODUCTS. This is done because the pyconf tool does not handle
167 # the . and - characters
168 for c in ".-": vv = vv.replace(c, "_")
171 if product_name in config.PRODUCTS:
172 # Search for the product description in the configuration
173 prod_info = get_product_section(config, product_name, vv, section)
175 # get salomeTool version
176 prod_info.sat_version = src.get_salometool_version(config)
178 # merge opt_depend in depend
179 if prod_info is not None and 'opt_depend' in prod_info:
180 for depend in prod_info.opt_depend:
181 if depend in config.APPLICATION.products:
182 prod_info.depend.append(depend,'')
185 # In case of a product get with a vcs,
186 # put the tag (equal to the version)
187 if prod_info is not None and prod_info.get_source in AVAILABLE_VCS:
189 if prod_info.get_source == 'git':
190 prod_info.git_info.tag = version
192 if prod_info.get_source == 'svn':
193 prod_info.svn_info.tag = version
195 if prod_info.get_source == 'cvs':
196 prod_info.cvs_info.tag = version
198 # In case of a fixed product,
199 # define the install_dir (equal to the version)
200 if prod_info is not None and \
201 (os.path.isdir(version) or version.startswith("/")):
202 # we consider a (fixed) path existing paths;
203 # or paths starting with '/' (the objective is to print a correct
204 # message to the user in case of non existing path.)
205 prod_info.install_dir = version
206 prod_info.get_source = "fixed"
208 # Check if the product is defined as native in the application
209 if prod_info is not None:
210 if version == "native":
211 prod_info.get_source = "native"
212 elif prod_info.get_source == "native":
213 msg = _("The product %(prod)s has version %(ver)s but is "
214 "declared as native in its definition" %
215 { 'prod': prod_info.name, 'ver': version})
216 raise src.SatException(msg)
218 # If there is no definition but the product is declared as native,
219 # construct a new definition containing only the get_source key
220 if prod_info is None and version == "native":
221 prod_info = src.pyconf.Config()
222 prod_info.name = product_name
223 prod_info.get_source = "native"
225 # If there is no definition but the product is fixed,
226 # construct a new definition containing only the product name
227 if prod_info is None and os.path.isdir(version):
228 prod_info = src.pyconf.Config()
229 prod_info.name = product_name
230 prod_info.get_source = "fixed"
231 prod_info.addMapping("environ", src.pyconf.Mapping(prod_info), "")
234 # If prod_info is still None, it means that there is no product definition
235 # in the config. The user has to provide it.
236 if prod_info is None:
237 prod_pyconf_path = src.find_file_in_lpath(product_name + ".pyconf",
238 config.PATHS.PRODUCTPATH)
239 if not prod_pyconf_path:
241 No definition found for the product %(1)s.
242 Please create a %(1)s.pyconf file somewhere in:
245 "2": PP.pformat(config.PATHS.PRODUCTPATH) }
248 No definition corresponding to the version %(1)s was found in the file:
250 Please add a section in it.""") % {"1" : vv, "2" : prod_pyconf_path}
251 raise src.SatException(msg)
253 # Set the debug, dev and version keys
254 prod_info.debug = debug
255 prod_info.verbose = verbose
258 prod_info.version = version
260 prod_info.base = base
262 # Set the archive_info if the product is get in archive mode
263 if prod_info.get_source == "archive":
264 if not "archive_info" in prod_info:
265 prod_info.addMapping("archive_info",
266 src.pyconf.Mapping(prod_info),
268 if "archive_name" in prod_info.archive_info:
269 arch_name = prod_info.archive_info.archive_name
270 elif "archive_prefix" in prod_info.archive_info:
271 arch_name = prod_info.archive_info.archive_prefix + "-" + version + ".tar.gz"
274 arch_name = product_name + "-" + version + ".tar.gz"
276 arch_path = src.find_file_in_lpath(arch_name,
277 config.PATHS.ARCHIVEPATH)
279 # arch_path is not found. It may generate an error in sat source,
280 # unless the archive is found in ftp serveur
281 prod_info.archive_info.archive_name = arch_name #without path
283 prod_info.archive_info.archive_name = arch_path
286 # If the product compiles with a script, check the script existence
287 # and if it is executable
288 if product_has_script(prod_info):
289 # Check the compil_script key existence
290 if "compil_script" not in prod_info:
292 No compilation script found for the product %s.
293 Please provide a 'compil_script' key in its definition.""") % product_name
294 raise src.SatException(msg)
296 # Get the path of the script file
297 # if windows supposed '.bat', if linux supposed '.sh'
298 # but user set extension script file in his pyconf as he wants, no obligation.
299 script = prod_info.compil_script
300 script_name = os.path.basename(script)
301 if script == script_name:
302 # Only a name is given. Search in the default directory
303 script_path = src.find_file_in_lpath(script_name, config.PATHS.PRODUCTPATH, "compil_scripts")
305 msg = _("Compilation script %s not found in") % script_name
306 DBG.tofix(msg, config.PATHS.PRODUCTPATH, True) # say where searched
307 script_path = "%s_(Not_Found_by_Sat!!)" % script_name
308 prod_info.compil_script = script_path
311 # Check that the script is executable
312 if os.path.exists(prod_info.compil_script) and not os.access(prod_info.compil_script, os.X_OK):
313 DBG.tofix("Compilation script file is not in 'execute mode'", prod_info.compil_script, True)
315 # Get the full paths of all the patches
316 if product_has_patches(prod_info):
319 for patch in prod_info.patches:
321 # If only a filename, then search for the patch in the PRODUCTPATH
322 if os.path.basename(patch_path) == patch_path:
323 # Search in the PRODUCTPATH/patches
324 patch_path = src.find_file_in_lpath(patch,
325 config.PATHS.PRODUCTPATH,
328 msg = _("Patch %(patch_name)s for %(prod_name)s not found:"
329 "\n" % {"patch_name" : patch,
330 "prod_name" : prod_info.name})
331 raise src.SatException(msg)
332 patches.append(patch_path)
334 DBG.tofix("problem in prod_info.patches", prod_info)
335 prod_info.patches = patches
337 # Get the full paths of the environment scripts
338 if product_has_env_script(prod_info):
339 env_script_path = prod_info.environ.env_script
340 # If only a filename, then search for the environment script
341 # in the PRODUCTPATH/env_scripts
342 if os.path.basename(env_script_path) == env_script_path:
343 # Search in the PRODUCTPATH/env_scripts
344 env_script_path = src.find_file_in_lpath(
345 prod_info.environ.env_script,
346 config.PATHS.PRODUCTPATH,
348 if not env_script_path:
349 msg = _("Environment script %(env_name)s for %(prod_name)s not "
350 "found.\n" % {"env_name" : env_script_path,
351 "prod_name" : prod_info.name})
352 raise src.SatException(msg)
354 prod_info.environ.env_script = env_script_path
357 # The variable with_install_dir is at false only for internal use
358 # of the function get_install_dir
360 # Save the install_dir key if there is any
361 if "install_dir" in prod_info and not "install_dir_save" in prod_info:
362 prod_info.install_dir_save = prod_info.install_dir
364 # if it is not the first time the install_dir is computed, it means
365 # that install_dir_save exists and it has to be taken into account.
366 if "install_dir_save" in prod_info:
367 prod_info.install_dir = prod_info.install_dir_save
369 # Set the install_dir key
370 prod_info.install_dir = get_install_dir(config, version, prod_info)
374 def get_product_section(config, product_name, version, section=None):
375 """Build the product description from the configuration
377 :param config Config: The global configuration
378 :param product_name str: The product name
379 :param version str: The version of the product as 'V8_4_0', or else.
380 :param section str: The searched section (if not None, the section is
382 :return: The product description
387 #get product definition and determine if the incremental definition mode is activated
388 aProd = config.PRODUCTS[product_name]
389 if "default" in aProd and\
390 "properties" in aProd.default and\
391 "incremental" in aProd.default.properties and\
392 aProd.default.properties.incremental == "yes":
393 # in this (new) mode the definition of the product is given by the default section
394 # and is incremented by others.
397 # in this (historic) mode the definition of the product is given by a full unique section
400 # decode version number
402 versionMMP = VMMP.MinorMajorPatch(version)
403 except: # example setuptools raise "minor in major_minor_patch is not integer: '0_6c11'"
406 # if a section is explicitely specified we select it
408 if section not in aProd:
410 # returns specific information for the given version
413 pi.from_file = aProd.from_file
415 # If it exists, get the information of the product_version
416 # ex: 'version_V6_6_0' as salome version classical syntax
417 elif "version_" + version in aProd:
418 # returns specific information for the given version
419 pi = aProd["version_" + version]
420 pi.section = "version_" + version
421 pi.from_file = aProd.from_file
423 # Else, check if there is a description for multiple versions
425 l_section_names = aProd.keys()
426 l_section_ranges = []
428 for name in l_section_names:
429 aRange = VMMP.getRange_majorMinorPatch(name)
430 if aRange is not None:
431 l_section_ranges.append((name, aRange))
433 if versionMMP is not None and len(l_section_ranges) > 0:
434 for name, (vmin, vmax) in l_section_ranges:
435 if versionMMP >= vmin and versionMMP <= vmax:
436 tagged.append((name, [vmin, vmax]))
439 DBG.write("multiple version ranges tagged for '%s', fix it" % version,
442 elif len(tagged) == 1: # ok
443 name, (vmin, vmax) = tagged[0]
446 pi.from_file = aProd.from_file
448 # Else, get the standard informations
449 elif "default" in aProd:
450 # returns the generic information (given version not found)
452 pi.section = "default"
453 pi.from_file = aProd.from_file
458 # If the definition is incremental, we take the default section
459 # and then complete it with other sections :
461 # - the selected section (pi)
462 # - the selected _win section
463 prod_info=aProd["default"]
464 prod_info.from_file = aProd.from_file
465 prod_info.section = "default"
466 if src.architecture.is_windows() and "default_win" in aProd:
467 for key in aProd["default_win"]:
468 prod_info[key]=aProd["default_win"][key]
469 if pi!=None and pi.section!="default":
470 # update prod_info with incremental definition contained in pi
472 prod_info[key]=pi[key]
473 win_section=pi.section+"_win"
474 if src.architecture.is_windows() and win_section in aProd:
475 for key in aProd[win_section]:
476 prod_info[key]=aProd[win_section][key]
480 #DBG.write("product info returned for product %s with version %s and section %s" %\
481 # (product_name, version, section), prod_info)
484 def get_install_dir(config, version, prod_info):
485 """Compute the installation directory of a given product
487 :param config Config: The global configuration
488 :param base str: This corresponds to the value given by user in its
489 application.pyconf for the specific product. If "yes", the
490 user wants the product to be in base. If "no", he wants the
491 product to be in the application workdir
492 :param version str: The version of the product
493 :param product_info Config: The configuration specific to
496 :return: The path of the product installation
501 # prod_info.base : corresponds to what is specified in application pyconf (either from the global key, or from a product dict)
502 # prod_info.install_dir : corresponds to what is specified in product pyconf (usually "base" for prerequisites)
503 if ( ("install_dir" in prod_info and prod_info.install_dir == "base")
504 or ("base" in prod_info and prod_info.base != "no") ):
505 # a product goes in base if install_dir is set to base, or if product was declared based in application pyconf
508 # what was declared in application has precedence over what was said in product pyconf
509 # no_base="yes" has precedence over base == "yes"
510 if ( ("base" in prod_info and prod_info.base == "no") or ("no_base" in config.APPLICATION
511 and config.APPLICATION.no_base == "yes")):
515 install_dir = get_base_install_dir(config, prod_info, version)
517 if "install_dir" not in prod_info or prod_info.install_dir == "base":
518 # Set it to the default value (in application directory)
519 if ( src.appli_test_property(config,"single_install_dir", "yes") and
520 src.product.product_test_property(prod_info,"single_install_dir", "yes")):
521 # when single_install_dir mode is activated in tha application
522 # we use config.INTERNAL.config.single_install_dir for products
523 # having single_install_dir property
524 install_dir = os.path.join(config.APPLICATION.workdir,
525 config.INTERNAL.config.install_dir,
526 config.INTERNAL.config.single_install_dir)
527 elif ( src.appli_test_property(config,"pip", "yes") and
528 src.product.product_test_property(prod_info,"pip", "yes") and
529 src.appli_test_property(config,"pip_install_dir", "python") ):
530 # when pip mode is activated in the application
531 # and product is pip, and pip_install_dir is set to python
532 # we assume python in installed in install_dir/Python
533 install_dir = os.path.join(config.APPLICATION.workdir,
534 config.INTERNAL.config.install_dir,
537 install_dir = os.path.join(config.APPLICATION.workdir,
538 config.INTERNAL.config.install_dir,
541 install_dir = prod_info.install_dir
545 def get_base_install_dir(config, prod_info, version):
546 """Compute the installation directory of a product in base
548 :param config Config: The global configuration
549 :param product_info Config: The configuration specific to
551 :param version str: The version of the product
552 :param base str: This corresponds to the value given by user in its
553 application.pyconf for the specific product. If "yes", the
554 user wants the product to be in base. If "no", he wants the
555 product to be in the application workdir.
556 if it contains something else, is is interpreted as the name
557 of a base we build for module load.
558 :return: The path of the product installation
561 if ( src.appli_test_property(config,"pip", "yes") and
562 src.product.product_test_property(prod_info,"pip", "yes") and
563 src.appli_test_property(config,"pip_install_dir", "python") ):
564 # when pip mode is activated in the application
565 # and product is pip, and pip_install_dir is set to python
566 python_info=get_product_config(config, "Python")
567 return python_info.install_dir
569 base_path = src.get_base_path(config)
570 if "base" in prod_info and prod_info.base != "no" and prod_info.base != "yes":
571 # we are in the case of a named base
572 prod_dir = os.path.join(base_path, "apps", prod_info.base, prod_info.name, version)
575 prod_dir = os.path.join(base_path, prod_info.name + "-" + version)
576 if not os.path.exists(prod_dir):
577 return os.path.join(prod_dir, "config-1")
579 exists, install_dir = check_config_exists(config, prod_dir, prod_info)
583 # Find the first config-<i> directory that is available in the product
588 install_dir = os.path.join(prod_dir, "config-%i" % label)
589 if os.path.exists(install_dir):
596 def add_compile_config_file(p_info, config):
597 '''Execute the proper configuration command(s)
598 in the product build directory.
600 :param p_info Config: The specific config of the product
601 :param config Config: The global configuration
603 # Create the compile config
604 # DBG.write("add_compile_config_file", p_info, True)
605 res = src.pyconf.Config()
606 res.addMapping(p_info.name, src.pyconf.Mapping(res), "")
607 res[p_info.name]= p_info.version
609 for prod_name in p_info.depend:
610 if prod_name not in res:
611 res.addMapping(prod_name, src.pyconf.Mapping(res), "")
612 prod_dep_info = src.product.get_product_config(config, prod_name, False)
613 res[prod_name] = prod_dep_info.version
614 # Write it in the install directory of the product
615 # This file is for automatic reading/checking
616 # see check_config_exists method
617 afilename = CONFIG_FILENAME + p_info.name + ".pyconf"
618 aFile = os.path.join(p_info.install_dir, afilename)
619 with open(aFile, 'w') as f:
622 # this file is not mandatory, is for human eye reading
623 afilename = PRODUCT_FILENAME + p_info.name + ".pyconf"
624 aFile = os.path.join(p_info.install_dir, afilename)
626 with open(aFile, 'w') as f:
627 p_info.__save__(f, evaluated=True) # evaluated expressions mode
629 # sometime some information cannot be evaluated.
630 # for example, in the context of non VCS archives, information on git server is not available.
631 DBG.write("Warning : sat was not able to evaluate and write down some information in file %s" % aFile)
634 def check_config_exists(config, prod_dir, prod_info, verbose=False):
636 Verify that the installation directory of a product in a base exists.
637 Check all the config-<i>/sat-config.py files found for correspondence
638 with current config and prod_info depend-version-tags
640 :param config Config: The global configuration
641 :param prod_dir str: The product installation directory path
643 :param product_info Config: The configuration specific to
645 :return: True or false is the installation is found or not
646 and if it is found, the path of the found installation
647 :rtype: (boolean, str)
649 # check if the directories or files of the directory corresponds to the
650 # directory installation of the product
651 if os.path.isdir(prod_dir):
652 l_dir_and_files = os.listdir(prod_dir)
654 raise Exception("Inexisting directory '%s'" % prod_dir)
656 DBG.write("check_config_exists 000", (prod_dir, l_dir_and_files), verbose)
657 DBG.write("check_config_exists 111", prod_info, verbose)
659 for dir_or_file in l_dir_and_files:
660 oExpr = re.compile(config_expression)
661 if not(oExpr.search(dir_or_file)):
662 # in mode BASE, not config-<i>, not interesting
663 # DBG.write("not interesting", dir_or_file, True)
665 # check if there is the file sat-config.pyconf file in the installation
667 afilename = CONFIG_FILENAME + prod_info.name + ".pyconf"
668 config_file = os.path.join(prod_dir, dir_or_file, afilename)
669 DBG.write("check_config_exists 222", config_file, verbose)
670 if not os.path.exists(config_file):
673 # check if there is the config described in the file corresponds the
674 # dependencies of the product
675 config_corresponds = True
676 compile_cfg = src.pyconf.Config(config_file)
677 for prod_dep in prod_info.depend:
678 # if the dependency is not in the config,
679 # the config does not correspond
680 if prod_dep not in compile_cfg:
681 config_corresponds = False
684 prod_dep_info = get_product_config(config, prod_dep, False)
685 # If the version of the dependency does not correspond,
686 # the config does not correspond
687 if prod_dep_info.version != compile_cfg[prod_dep]:
688 config_corresponds = False
691 if config_corresponds:
692 for prod_name in compile_cfg:
693 # assume new compatibility with prod_name in sat-config.pyconf files
694 if prod_name == prod_info.name:
695 if prod_info.version == compile_cfg[prod_name]:
696 DBG.write("check_config_exists OK 333", compile_cfg, verbose)
698 else: # no correspondence with newer with prod_name sat-config.pyconf files
699 config_corresponds = False
702 # as old compatibility without prod_name sat-config.pyconf files
703 if prod_name not in prod_info.depend:
704 # here there is an unexpected depend in an old compilation
705 config_corresponds = False
708 if config_corresponds: # returns (and stops) at first correspondence found
709 DBG.write("check_config_exists OK 444", dir_or_file, verbose)
710 return True, os.path.join(prod_dir, dir_or_file)
712 # no correspondence found
717 def get_products_infos(lproducts, config):
718 """Get the specific configuration of a list of products
720 :param lproducts List: The list of product names
721 :param config Config: The global configuration
722 :return: the list of tuples
723 (product name, specific configuration of the product)
724 :rtype: [(str, Config)]
727 # Loop on product names
728 for prod in lproducts:
729 # Get the specific configuration of the product
730 prod_info = get_product_config(config, prod)
731 if prod_info is not None:
732 products_infos.append((prod, prod_info))
734 msg = _("The %s product has no definition in the configuration.") % prod
735 raise src.SatException(msg)
736 return products_infos
739 def get_products_list(options, cfg, logger):
741 method that gives the product list with their informations from
742 configuration regarding the passed options.
744 :param options Options: The Options instance that stores the commands arguments
745 :param cfg Config: The global configuration
746 :param logger Logger: The logger instance to use for the display and logging
747 :return: The list of (product name, product_informations).
750 # Get the products to be prepared, regarding the options
751 if options.products is None:
752 # No options, get all products sources
753 products = cfg.APPLICATION.products
755 # if option --products, check that all products of the command line
756 # are present in the application.
757 """products = options.products
759 if p not in cfg.APPLICATION.products:
760 raise src.SatException(_("Product %(product)s "
761 "not defined in application %(application)s") %
762 { 'product': p, 'application': cfg.VARS.application} )"""
764 products = src.getProductNames(cfg, options.products, logger)
766 # Construct the list of tuple containing
767 # the products name and their definition
768 resAll = src.product.get_products_infos(products, cfg)
770 # if the property option was passed, filter the list
771 if options.properties: # existing properties
775 prop, value = options.properties # for example 'is_SALOME_module', 'yes'
776 for p_name, p_info in resAll:
778 if p_info.properties[prop] == value:
779 res.append((p_name, p_info))
786 if len(ok) != len(resAll):
787 logger.trace("on properties %s\n products accepted:\n %s\n products rejected:\n %s\n" %
788 (options.properties, PP.pformat(sorted(ok)), PP.pformat(sorted(ko))))
790 logger.warning("properties %s\n seems useless with no products rejected" %
791 (options.properties))
793 res = resAll # not existing properties as all accepted
798 def get_product_dependencies(config, product_info):
800 Get recursively the list of products that are
801 in the product_info dependencies
803 :param config Config: The global configuration
804 :param product_info Config: The configuration specific to
806 :return: the list of products in dependence
809 if "depend" not in product_info or product_info.depend == []:
812 for prod in product_info.depend:
813 if prod == product_info.name:
817 prod_info = get_product_config(config, prod)
818 dep_prod = get_product_dependencies(config, prod_info)
819 for prod_in_dep in dep_prod:
820 if prod_in_dep not in res:
821 res.append(prod_in_dep)
824 def check_installation(config, product_info):
826 Verify if a product is well installed. Checks install directory presence
827 and some additional files if it is defined in the config
829 :param product_info Config: The configuration specific to
831 :return: True if it is well installed
834 if not product_compiles(product_info):
837 install_dir = product_info.install_dir
838 if ( (src.appli_test_property(config,"single_install_dir", "yes") and
839 src.product.product_test_property(product_info,"single_install_dir", "yes")) or
840 (src.appli_test_property(config,"pip", "yes") and
841 src.product.product_test_property(product_info,"pip", "yes") and
842 src.appli_test_property(config,"pip_install_dir", "python") ) ):
843 # if the product is installed in the single install dir, or in python (for pip managed products)
844 # we check the product file in state of the install directory.
845 filename = CONFIG_FILENAME + product_info.name + ".pyconf"
846 if not os.path.exists(os.path.join(install_dir, filename)):
849 if not os.path.exists(install_dir):
852 # check extra files if specified in present_files.install section
853 if ("present_files" in product_info and
854 "install" in product_info.present_files):
855 for file_relative_path in product_info.present_files.install:
856 file_path = os.path.join(install_dir, file_relative_path)
857 if not os.path.exists(file_path):
861 def check_source(product_info):
862 """Verify if a sources of product is preset. Checks source directory presence
864 :param product_info Config: The configuration specific to
866 :return: True if it is well installed
869 source_dir = product_info.source_dir
870 if not os.path.exists(source_dir):
872 if ("present_files" in product_info and
873 "source" in product_info.present_files):
874 for file_relative_path in product_info.present_files.source:
875 file_path = os.path.join(source_dir, file_relative_path)
876 if not os.path.exists(file_path):
880 def product_is_salome(product_info):
881 """Know if a product is a SALOME module
883 :param product_info Config: The configuration specific to
885 :return: True if the product is a SALOME module, else False
888 return ("properties" in product_info and
889 "is_SALOME_module" in product_info.properties and
890 product_info.properties.is_SALOME_module == "yes")
892 def product_is_fixed(product_info):
893 """Know if a product is fixed
895 :param product_info Config: The configuration specific to
897 :return: True if the product is fixed, else False
900 get_src = product_info.get_source
901 return get_src.lower() == 'fixed'
903 def product_is_native(product_info):
904 """Know if a product is native
906 :param product_info Config: The configuration specific to
908 :return: True if the product is native, else False
911 get_src = product_info.get_source
912 return get_src.lower() == 'native'
914 def product_is_dev(product_info):
915 """Know if a product is in dev mode
917 :param product_info Config: The configuration specific to
919 :return: True if the product is in dev mode, else False
922 dev = product_info.dev
923 res = (dev.lower() == 'yes')
924 DBG.write('product_is_dev %s' % product_info.name, res)
925 # if product_info.name == "XDATA": return True #test #10569
928 def product_is_hpc(product_info):
929 """Know if a product is in hpc mode
931 :param product_info Config: The configuration specific to
933 :return: True if the product is in hpc mode, else False
936 hpc = product_info.hpc
937 res = (hpc.lower() == 'yes')
940 def product_is_debug(product_info):
941 """Know if a product is in debug mode
943 :param product_info Config: The configuration specific to
945 :return: True if the product is in debug mode, else False
948 debug = product_info.debug
949 return debug.lower() == 'yes'
951 def product_is_verbose(product_info):
952 """Know if a product is in verbose mode
954 :param product_info Config: The configuration specific to
956 :return: True if the product is in verbose mode, else False
959 verbose = product_info.verbose
960 return verbose.lower() == 'yes'
962 def product_is_autotools(product_info):
963 """Know if a product is compiled using the autotools
965 :param product_info Config: The configuration specific to
967 :return: True if the product is autotools, else False
970 build_src = product_info.build_source
971 return build_src.lower() == 'autotools'
973 def product_is_cmake(product_info):
974 """Know if a product is compiled using the cmake
976 :param product_info Config: The configuration specific to
978 :return: True if the product is cmake, else False
981 build_src = product_info.build_source
982 return build_src.lower() == 'cmake'
984 def product_is_vcs(product_info):
985 """Know if a product is download using git, svn or cvs (not archive)
987 :param product_info Config: The configuration specific to
989 :return: True if the product is vcs, else False
992 return product_info.get_source in AVAILABLE_VCS
994 def product_is_smesh_plugin(product_info):
995 """Know if a product is a SMESH plugin
997 :param product_info Config: The configuration specific to
999 :return: True if the product is a SMESH plugin, else False
1002 return ("properties" in product_info and
1003 "smesh_plugin" in product_info.properties and
1004 product_info.properties.smesh_plugin == "yes")
1006 def product_is_cpp(product_info):
1007 """Know if a product is cpp
1009 :param product_info Config: The configuration specific to
1011 :return: True if the product is a cpp, else False
1014 return ("properties" in product_info and
1015 "cpp" in product_info.properties and
1016 product_info.properties.cpp == "yes")
1018 def product_compiles(product_info):
1020 Know if a product compiles or not
1021 (some products do not have a compilation procedure)
1023 :param product_info Config: The configuration specific to
1025 :return: True if the product compiles, else False
1028 return not("properties" in product_info and
1029 "compilation" in product_info.properties and
1030 product_info.properties.compilation == "no")
1032 def product_has_script(product_info):
1033 """Know if a product has a compilation script
1035 :param product_info Config: The configuration specific to
1037 :return: True if the product it has a compilation script, else False
1040 if "build_source" not in product_info:
1043 build_src = product_info.build_source
1044 return build_src.lower() == 'script'
1046 def product_has_env_script(product_info):
1047 """Know if a product has an environment script
1049 :param product_info Config: The configuration specific to
1051 :return: True if the product it has an environment script, else False
1054 return "environ" in product_info and "env_script" in product_info.environ
1056 def product_has_patches(product_info):
1057 """Know if a product has one or more patches
1059 :param product_info Config: The configuration specific to
1061 :return: True if the product has one or more patches
1064 res = ( "patches" in product_info and len(product_info.patches) > 0 )
1067 def product_has_logo(product_info):
1068 """Know if a product has a logo (YACSGEN generate)
1070 :param product_info Config: The configuration specific to
1072 :return: The path of the logo if the product has a logo, else False
1075 if ("properties" in product_info and
1076 "logo" in product_info.properties):
1077 return product_info.properties.logo
1081 def product_has_licence(product_info, path):
1082 """Find out if a product has a licence
1084 :param product_info Config: The configuration specific to the product
1085 :param path Str: The path where to search for the licence
1086 :return: The name of the licence file (the complete path if it is found in the path, else the name, else False
1089 if ("properties" in product_info and
1090 "licence" in product_info.properties):
1091 licence_name = product_info.properties.licence
1093 # search for licence_name in path
1094 # a- consolidate the path into one signe string licence_path
1095 licence_path=path[0]
1096 for lpath in path[1:]:
1097 licence_path=licence_path+":"+lpath
1098 licence_path_list=licence_path.split(":")
1099 licence_fullname = src.find_file_in_lpath(licence_name, licence_path_list)
1100 if licence_fullname:
1101 return licence_fullname
1103 # if the search of licence in path failed, we return its name (not the full path)
1107 return False # product has no licence
1109 def product_has_salome_gui(product_info):
1110 """Know if a product has a SALOME gui
1112 :param product_info Config: The configuration specific to
1114 :return: True if the product has a SALOME gui, else False
1117 return ("properties" in product_info and
1118 "has_salome_gui" in product_info.properties and
1119 product_info.properties.has_salome_gui == "yes")
1121 def product_is_mpi(product_info):
1122 """Know if a product has openmpi in its dependencies
1124 :param product_info Config: The configuration specific to
1126 :return: True if the product has openmpi inits dependencies
1129 return "openmpi" in product_info.depend
1131 def product_is_generated(product_info):
1132 """Know if a product is generated (YACSGEN)
1134 :param product_info Config: The configuration specific to
1136 :return: True if the product is generated
1139 return ("properties" in product_info and
1140 "generate" in product_info.properties and
1141 product_info.properties.generate == "yes")
1143 def product_is_compile_time(product_info):
1144 """Know if a product is only used at compile time
1146 :param product_info Config: The configuration specific to
1148 :return: True if the product is only used at compile time
1151 return ("properties" in product_info and
1152 "compile_time" in product_info.properties and
1153 product_info.properties.compile_time == "yes")
1156 def product_test_property(product_info, property_name, property_value):
1157 """Generic function to test if a product has a property set to a value
1159 :param product_info Config: The configuration specific to
1161 :param property_name : The name of the property to check
1162 :param property_value : The value of the property to test
1163 :return: True if the product has the property and the property is set to property_value
1166 # first check if product has the property
1167 if not ("properties" in product_info and
1168 property_name in product_info.properties):
1171 # then check to the property is set to property_value
1172 eval_expression = 'product_info.properties.%s == "%s"' % (property_name,property_value)
1173 result = eval(eval_expression)
1178 def get_product_components(product_info):
1179 """Get the component list to generate with the product
1181 :param product_info Config: The configuration specific to
1183 :return: The list of names of the components
1187 if not product_is_generated(product_info):
1191 if "component_name" in product_info:
1192 compo_list = product_info.component_name
1194 if isinstance(compo_list, str):
1195 compo_list = [ compo_list ]
1198 def product_is_wheel(product_info):
1199 """ tells whether a product is a wheel
1201 :param product_info Config: The configuration specific to
1203 :return: True if the product has a wheel, else False
1206 return ("properties" in product_info and
1207 "is_wheel" in product_info.properties and
1208 product_info.properties.is_wheel == "yes")