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