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
18 '''In this file are implemented the classes and methods
19 relative to the product notion of salomeTools
24 AVAILABLE_VCS = ['git', 'svn', 'cvs']
26 def get_product_config(config, product_name, version):
27 '''Get the specific configuration of a product from the global configuration
29 :param config Config: The global configuration
30 :param product_name str: The name of the product
31 :param version str: The version of the product
32 :return: the specific configuration of the product
36 # substitute some character with _
37 for c in ".-": vv = vv.replace(c, "_")
38 full_product_name = product_name + '_' + vv
41 # If it exists, get the information of the product_version
42 if full_product_name in config.PRODUCTS:
43 # returns specific information for the given version
44 prod_info = config.PRODUCTS[full_product_name]
45 # Get the standard informations
46 elif product_name in config.PRODUCTS:
47 # returns the generic information (given version not found)
48 prod_info = config.PRODUCTS[product_name]
50 # merge opt_depend in depend
51 if prod_info is not None and 'opt_depend' in prod_info:
52 for depend in prod_info.opt_depend:
53 if depend in config.PRODUCTS:
54 prod_info.depend.append(depend,'')
56 # Check if the product is defined as native in the application
59 # In case of a product get with a vcs, put the tag (equal to the version)
60 if prod_info is not None and prod_info.get_source in AVAILABLE_VCS:
62 if prod_info.get_source == 'git':
63 prod_info.git_info.tag = version
65 if prod_info.get_source == 'svn':
66 prod_info.svn_info.tag = version
68 if prod_info.get_source == 'cvs':
69 prod_info.cvs_info.tag = version
71 # In case of a fixed product, define the install_dir (equal to the version)
72 if prod_info is not None and prod_info.get_source=="fixed":
73 prod_info.install_dir = version
77 def get_products_infos(lproducts, config):
78 '''Get the specific configuration of a list of products
80 :param lproducts List: The list of product names
81 :param config Config: The global configuration
82 :return: the list of tuples
83 (product name, specific configuration of the product)
84 :rtype: [(str, Config)]
87 # Loop on product names
88 for prod in lproducts:
89 # Get the version of the product from the application definition
90 version_prod = config.APPLICATION.products[prod]
91 # if no version, then take the default one defined in the application
92 if isinstance(version_prod, bool):
93 version_prod = config.APPLICATION.tag
95 # Get the specific configuration of the product
96 prod_info = get_product_config(config, prod, version_prod)
97 if prod_info is not None:
98 products_infos.append((prod, prod_info))
100 msg = _("The %s product has no definition in the configuration.") % prod
101 raise src.SatException(msg)
102 return products_infos
105 def product_is_sample(product_info):
106 '''Know if a product has the sample type
108 :param product_info Config: The configuration specific to
110 :return: True if the product has the sample type, else False
113 mtype = product_info.type
114 return mtype.lower() == 'sample'
116 def product_is_fixed(product_info):
117 '''Know if a product is fixed
119 :param product_info Config: The configuration specific to
121 :return: True if the product is fixed, else False
124 get_src = product_info.get_source
125 return get_src.lower() == 'fixed'