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 method
19 relative to the module notion of salomeTools
24 def get_module_config(config, module_name, version):
25 '''Get the specific configuration of a module from the global configuration
27 :param config Config: The global configuration
28 :param module_name str: The name of the module
29 :param version str: The version of the module
30 :return: the specific configuration of the module
34 # substitute some character with _
35 for c in ".-": vv = vv.replace(c, "_")
36 full_module_name = module_name + '_' + vv
39 # If it exists, get the information of the module_version
40 if full_module_name in config.MODULES:
41 # returns specific information for the given version
42 mod_info = config.MODULES[full_module_name]
43 # Get the standard informations
44 elif module_name in config.MODULES:
45 # returns the generic information (given version not found)
46 mod_info = config.MODULES[module_name]
48 # merge opt_depend in depend
49 if mod_info is not None and 'opt_depend' in mod_info:
50 for depend in mod_info.opt_depend:
51 if depend in config.MODULES:
52 mod_info.depend.append(depend,'')
55 def get_modules_infos(lmodules, config):
56 '''Get the specific configuration of a list of modules
58 :param lmodules List: The list of module names
59 :param config Config: The global configuration
60 :return: the list of tuples
61 (module name, specific configuration of the module)
62 :rtype: [(str, Config)]
65 # Loop on module names
67 # Get the version of the module from the application definition
68 version_mod = config.APPLICATION.modules[mod][0]
69 # Get the specific configuration of the module
70 mod_info = get_module_config(config, mod, version_mod)
71 if mod_info is not None:
72 modules_infos.append((mod, mod_info))
74 msg = _("The %s module has no definition in the configuration.") % mod
75 raise src.SatException(msg)
79 def module_is_sample(module_info):
80 '''Know if a module has the sample type
82 :param module_info Config: The configuration specific to
83 the module to be prepared
84 :return: True if the module has the sample type, else False
87 mtype = module_info.module_type
88 return mtype.lower() == 'sample'