Salome HOME
Rename software into modules. Add first version of source command, it handle git...
[tools/sat.git] / src / module.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
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.
9 #
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.
14 #
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
19 import src
20
21 def get_module_config(config, module_name, version):
22     vv = version
23     for c in ".-": vv = vv.replace(c, "_") # substitute some character with _
24     full_module_name = module_name + '_' + vv
25
26     mod_info = None
27     if full_module_name in config.MODULES:
28         # returns specific information for the given version
29         mod_info = config.MODULES[full_module_name]    
30
31     elif module_name in config.MODULES:
32         # returns the generic information (given version not found)
33         mod_info = config.MODULES[module_name]
34     
35     # merge opt_depend in depend
36     if mod_info is not None and 'opt_depend' in mod_info:
37         for depend in mod_info.opt_depend:
38             if depend in config.MODULES:
39                 mod_info.depend.append(depend,'')
40     return mod_info
41
42 def get_modules_infos(lmodules, config):
43     modules_infos = []
44     for mod in lmodules:
45         version_mod = config.APPLICATION.modules[mod][0]
46         mod_info = get_module_config(config, mod, version_mod)
47         if mod_info is not None:
48             modules_infos.append((mod, mod_info))
49         else:
50             msg = _("The %s module has no definition in the configuration.") % mod
51             raise src.SatException(msg)
52     return modules_infos
53
54
55 def module_is_sample(module_info): 
56     mtype = module_info.module_type
57     return mtype.lower() == 'sample'