]> SALOME platform Git repositories - tools/sat.git/blob - src/module.py
Salome HOME
continue
[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 '''In this file are implemented the classes and methods 
19    relative to the module notion of salomeTools
20 '''
21
22 import src
23
24 AVAILABLE_VCS = ['git', 'svn', 'cvs']
25
26 def get_module_config(config, module_name, version):
27     '''Get the specific configuration of a module from the global configuration
28     
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
33     :rtype: Config
34     '''
35     vv = version
36     # substitute some character with _
37     for c in ".-": vv = vv.replace(c, "_")
38     full_module_name = module_name + '_' + vv
39
40     mod_info = None
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]
49     
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,'')
55                 
56     # Check if the module is defined as native in the application
57     pass # to be done
58     
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:
61         
62         if mod_info.get_sources == 'git':
63             mod_info.git_info.tag = version
64         
65         if mod_info.get_sources == 'svn':
66             mod_info.svn_info.tag = version
67         
68         if mod_info.get_sources == 'cvs':
69             mod_info.cvs_info.tag = version
70     
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
74     
75     return mod_info
76
77 def get_modules_infos(lmodules, config):
78     '''Get the specific configuration of a list of modules
79     
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)]
85     '''
86     modules_infos = []
87     # Loop on module names
88     for mod in lmodules:
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
94         
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))
99         else:
100             msg = _("The %s module has no definition in the configuration.") % mod
101             raise src.SatException(msg)
102     return modules_infos
103
104
105 def module_is_sample(module_info):
106     '''Know if a module has the sample type
107     
108     :param module_info Config: The configuration specific to 
109                                the module
110     :return: True if the module has the sample type, else False
111     :rtype: boolean
112     '''
113     mtype = module_info.type
114     return mtype.lower() == 'sample'
115
116 def module_is_fixed(module_info):
117     '''Know if a module is fixed
118     
119     :param module_info Config: The configuration specific to 
120                                the module
121     :return: True if the module is fixed, else False
122     :rtype: boolean
123     '''
124     get_src = module_info.get_sources
125     return get_src.lower() == 'fixed'