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
26 AVAILABLE_VCS = ['git', 'svn', 'cvs']
28 def get_product_config(config, product_name):
29 '''Get the specific configuration of a product from the global configuration
31 :param config Config: The global configuration
32 :param product_name str: The name of the product
33 :return: the specific configuration of the product
37 # Get the version of the product from the application definition
38 version = config.APPLICATION.products[product_name]
39 # if no version, then take the default one defined in the application
40 if isinstance(version, bool):
41 version = config.APPLICATION.tag
43 # Define debug and dev modes
44 # Get the tag if a dictionary is given in APPLICATION.products for the
48 if isinstance(version, src.pyconf.Mapping):
51 if not 'tag' in dic_version:
52 version = config.APPLICATION.tag
54 version = dic_version.tag
56 # Get the debug if any
57 if 'debug' in dic_version:
58 debug = dic_version.debug
61 if 'dev' in dic_version:
65 # substitute some character with _ in order to get the correct definition
66 # in config.PRODUCTS. This is done because the pyconf tool does not handle
67 # the . and - characters
68 for c in ".-": vv = vv.replace(c, "_")
69 full_product_name = product_name + '_' + vv
72 # If it exists, get the information of the product_version
73 if full_product_name in config.PRODUCTS:
74 # returns specific information for the given version
75 prod_info = config.PRODUCTS[full_product_name]
76 # Get the standard informations
77 elif product_name in config.PRODUCTS:
78 # returns the generic information (given version not found)
79 prod_info = config.PRODUCTS[product_name]
81 # merge opt_depend in depend
82 if prod_info is not None and 'opt_depend' in prod_info:
83 for depend in prod_info.opt_depend:
84 if depend in config.PRODUCTS:
85 prod_info.depend.append(depend,'')
87 # In case of a product get with a vcs, put the tag (equal to the version)
88 if prod_info is not None and prod_info.get_source in AVAILABLE_VCS:
90 if prod_info.get_source == 'git':
91 prod_info.git_info.tag = version
93 if prod_info.get_source == 'svn':
94 prod_info.svn_info.tag = version
96 if prod_info.get_source == 'cvs':
97 prod_info.cvs_info.tag = version
99 # In case of a fixed product, define the install_dir (equal to the version)
100 if prod_info is not None and prod_info.get_source=="fixed":
101 prod_info.install_dir = version
103 # Check if the product is defined as native in the application
104 if prod_info is not None:
105 if version == "native":
106 prod_info.get_source = "native"
107 elif prod_info.get_source == "native":
108 msg = _("The product %(prod)s has version %(ver)s but is declared"
109 " as native in its definition" %
110 { 'prod': prod_info.name, 'ver': version})
111 raise src.SatException(msg)
113 # If there is no definition but the product is declared as native,
114 # construct a new definition containing only the get_source key
115 if prod_info is None and version == "native":
116 prod_info = src.pyconf.Config()
117 prod_info.name = product_name
118 prod_info.get_source = "native"
120 # If prod_info is still None, it means that there is no product definition
121 # in the config. The user has to provide it.
122 if prod_info is None:
123 msg = _("No definition found for the product %s\n"
124 "Please create a %s.pyconf file." % (product_name, product_name))
125 raise src.SatException(msg)
127 # Set the debug, dev and version keys
128 prod_info.debug = debug
130 prod_info.version = version
132 # Set the install_dir key
133 if "install_dir" not in prod_info:
134 # Set it to the default value (in application directory)
135 prod_info.install_dir = os.path.join(config.APPLICATION.workdir,
139 if prod_info.install_dir == "base":
140 # Get the product base of the application
141 base_path = src.get_base_path(config)
142 prod_info.install_dir = os.path.join(base_path,
143 prod_info.name + version)
145 # If the product compiles with a script, check the script existence
146 # and if it is executable
147 if product_has_script(prod_info):
148 # Check the compil_script key existence
149 if "compil_script" not in prod_info:
150 msg = _("No compilation script found for the product %s\n"
151 "Please provide a \"compil_script\" key in its definition."
153 raise src.SatException(msg)
155 # Get the path of the script
156 script = prod_info.compil_script
157 script_name = os.path.basename(script)
158 if script == script_name:
159 # Only a name is given. Search in the default directory
160 script_path = os.path.join(
161 config.INTERNAL.compile.default_script_dir, script_name)
162 prod_info.compil_script = script_path
164 # Check script existence
165 if not os.path.exists(prod_info.compil_script):
166 raise src.SatException(_("Compilation script not found: %s") %
167 prod_info.compil_script)
169 # Check that the script is executable
170 if not os.access(prod_info.compil_script, os.X_OK):
171 raise src.SatException(
172 _("Compilation script cannot be executed: %s") %
173 prod_info.compil_script)
177 def get_products_infos(lproducts, config):
178 '''Get the specific configuration of a list of products
180 :param lproducts List: The list of product names
181 :param config Config: The global configuration
182 :return: the list of tuples
183 (product name, specific configuration of the product)
184 :rtype: [(str, Config)]
187 # Loop on product names
188 for prod in lproducts:
189 # Get the specific configuration of the product
190 prod_info = get_product_config(config, prod)
191 if prod_info is not None:
192 products_infos.append((prod, prod_info))
194 msg = _("The %s product has no definition in the configuration.") % prod
195 raise src.SatException(msg)
196 return products_infos
198 def get_product_dependencies(config, product_info):
199 '''Get recursively the list of products that are
200 in the product_info dependencies
202 :param config Config: The global configuration
203 :param product_info Config: The configuration specific to
205 :return: the list of products in dependence
208 if "depend" not in product_info or product_info.depend == []:
211 for prod in product_info.depend:
214 prod_info = get_product_config(config, prod)
215 dep_prod = get_product_dependencies(config, prod_info)
216 for prod_in_dep in dep_prod:
217 if prod_in_dep not in res:
218 res.append(prod_in_dep)
221 def product_is_sample(product_info):
222 '''Know if a product has the sample type
224 :param product_info Config: The configuration specific to
226 :return: True if the product has the sample type, else False
229 if 'type' in product_info:
230 ptype = product_info.type
231 return ptype.lower() == 'sample'
235 def product_is_salome(product_info):
236 '''Know if a product is of type salome
238 :param product_info Config: The configuration specific to
240 :return: True if the product is salome, else False
243 if 'type' in product_info:
244 ptype = product_info.type
245 return ptype.lower() == 'salome'
249 def product_is_fixed(product_info):
250 '''Know if a product is fixed
252 :param product_info Config: The configuration specific to
254 :return: True if the product is fixed, else False
257 get_src = product_info.get_source
258 return get_src.lower() == 'fixed'
260 def product_is_native(product_info):
261 '''Know if a product is native
263 :param product_info Config: The configuration specific to
265 :return: True if the product is native, else False
268 get_src = product_info.get_source
269 return get_src.lower() == 'native'
271 def product_is_dev(product_info):
272 '''Know if a product is in dev mode
274 :param product_info Config: The configuration specific to
276 :return: True if the product is in dev mode, else False
279 dev = product_info.dev
280 return dev.lower() == 'yes'
282 def product_is_debug(product_info):
283 '''Know if a product is in debug mode
285 :param product_info Config: The configuration specific to
287 :return: True if the product is in debug mode, else False
290 debug = product_info.debug
291 return debug.lower() == 'yes'
293 def product_is_autotools(product_info):
294 '''Know if a product is compiled using the autotools
296 :param product_info Config: The configuration specific to
298 :return: True if the product is autotools, else False
301 build_src = product_info.build_source
302 return build_src.lower() == 'autotools'
304 def product_is_cmake(product_info):
305 '''Know if a product is compiled using the cmake
307 :param product_info Config: The configuration specific to
309 :return: True if the product is cmake, else False
312 build_src = product_info.build_source
313 return build_src.lower() == 'cmake'
315 def product_has_script(product_info):
316 '''Know if a product has a compilation script
318 :param product_info Config: The configuration specific to
320 :return: True if the product it has a compilation script, else False
323 if "build_source" not in product_info:
326 build_src = product_info.build_source
327 return build_src.lower() == 'script'