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):
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 :return: the specific configuration of the product
35 # Get the version of the product from the application definition
36 version = config.APPLICATION.products[product_name]
37 # if no version, then take the default one defined in the application
38 if isinstance(version, bool):
39 version = config.APPLICATION.tag
41 # Define debug and dev modes
42 # Get the tag if a dictionary is given in APPLICATION.products for the
46 if isinstance(version, src.pyconf.Mapping):
49 if not 'tag' in dic_version:
50 version = config.APPLICATION.tag
52 version = dic_version.tag
54 # Get the debug if any
55 if 'debug' in dic_version:
56 debug = dic_version.debug
59 if 'dev' in dic_version:
63 # substitute some character with _ in order to get the correct definition
64 # in config.PRODUCTS. This is done because the pyconf tool does not handle
65 # the . and - characters
66 for c in ".-": vv = vv.replace(c, "_")
67 full_product_name = product_name + '_' + vv
70 # If it exists, get the information of the product_version
71 if full_product_name in config.PRODUCTS:
72 # returns specific information for the given version
73 prod_info = config.PRODUCTS[full_product_name]
74 # Get the standard informations
75 elif product_name in config.PRODUCTS:
76 # returns the generic information (given version not found)
77 prod_info = config.PRODUCTS[product_name]
79 # merge opt_depend in depend
80 if prod_info is not None and 'opt_depend' in prod_info:
81 for depend in prod_info.opt_depend:
82 if depend in config.PRODUCTS:
83 prod_info.depend.append(depend,'')
85 # In case of a product get with a vcs, put the tag (equal to the version)
86 if prod_info is not None and prod_info.get_source in AVAILABLE_VCS:
88 if prod_info.get_source == 'git':
89 prod_info.git_info.tag = version
91 if prod_info.get_source == 'svn':
92 prod_info.svn_info.tag = version
94 if prod_info.get_source == 'cvs':
95 prod_info.cvs_info.tag = version
97 # In case of a fixed product, define the install_dir (equal to the version)
98 if prod_info is not None and prod_info.get_source=="fixed":
99 prod_info.install_dir = version
101 # Check if the product is defined as native in the application
102 if prod_info is not None:
103 if version == "native":
104 prod_info.get_source = "native"
105 elif prod_info.get_source == "native":
106 msg = _("The product %(prod)s has version %(ver)s but is declared"
107 " as native in its definition" %
108 { 'prod': prod_info.name, 'ver': version})
109 raise src.SatException(msg)
111 # If there is no definition but the product is declared as native,
112 # construct a new defifnition containing only the get_source key
113 if prod_info is None and version == "native":
114 prod_info = src.pyconf.Config()
115 prod_info.name = product_name
116 prod_info.get_source = "native"
118 # Set the debug and dev keys
119 if prod_info is not None:
120 prod_info.debug = debug
125 def get_products_infos(lproducts, config):
126 '''Get the specific configuration of a list of products
128 :param lproducts List: The list of product names
129 :param config Config: The global configuration
130 :return: the list of tuples
131 (product name, specific configuration of the product)
132 :rtype: [(str, Config)]
135 # Loop on product names
136 for prod in lproducts:
137 # Get the specific configuration of the product
138 prod_info = get_product_config(config, prod)
139 if prod_info is not None:
140 products_infos.append((prod, prod_info))
142 msg = _("The %s product has no definition in the configuration.") % prod
143 raise src.SatException(msg)
144 return products_infos
147 def product_is_sample(product_info):
148 '''Know if a product has the sample type
150 :param product_info Config: The configuration specific to
152 :return: True if the product has the sample type, else False
155 if 'type' in product_info:
156 ptype = product_info.type
157 return ptype.lower() == 'sample'
161 def product_is_fixed(product_info):
162 '''Know if a product is fixed
164 :param product_info Config: The configuration specific to
166 :return: True if the product is fixed, else False
169 get_src = product_info.get_source
170 return get_src.lower() == 'fixed'
172 def product_is_native(product_info):
173 '''Know if a product is native
175 :param product_info Config: The configuration specific to
177 :return: True if the product is native, else False
180 get_src = product_info.get_source
181 return get_src.lower() == 'native'
183 def product_is_dev(product_info):
184 '''Know if a product is in dev mode
186 :param product_info Config: The configuration specific to
188 :return: True if the product is in dev mode, else False
191 dev = product_info.dev
192 return dev.lower() == 'yes'
194 def product_is_debug(product_info):
195 '''Know if a product is in debug mode
197 :param product_info Config: The configuration specific to
199 :return: True if the product is in debug mode, else False
202 debug = product_info.debug
203 return debug.lower() == 'yes'