]> SALOME platform Git repositories - tools/sat.git/blob - commands/prepare.py
Salome HOME
Add prepare command
[tools/sat.git] / commands / prepare.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 # Define all possible option for log command :  sat log <options>
22 parser = src.options.Options()
23 parser.add_option('m', 'module', 'list2', 'modules',
24     _('modules to prepare. This option can be'
25     ' passed several time to prepare several modules.'))
26 parser.add_option('', 'no_sample', 'boolean', 'no_sample', 
27     _("do not prepare sample modules."))
28 parser.add_option('f', 'force', 'boolean', 'force', 
29     _("force to prepare the modules in development mode."))
30
31 def description():
32     '''method that is called when salomeTools is called with --help option.
33     
34     :return: The text to display for the prepare command description.
35     :rtype: str
36     '''
37     return _("The prepare command apply the patches on the sources of "
38              "the application modules if there is any")
39   
40 def run(args, runner, logger):
41     '''method that is called when salomeTools is called with prepare parameter.
42     '''
43     
44     # Parse the options
45     (options, args) = parser.parse_args(args)
46
47     # check that the command has been called with an application
48     src.check_config_has_application( runner.cfg )
49
50     # Construct the option to pass to the source command
51     args_source = runner.cfg.VARS.application + ' '
52     
53     if options.modules:
54         args_source += '--module ' + ','.join(options.modules)
55     
56     if options.no_sample:
57         args_source += ' --no_sample'
58         
59     if options.force:
60         args_source += ' --force'
61     
62     # Call the source command that gets the source
63     msg = src.printcolors.printcHeader(
64                                 _('Get the sources of the desired modules\n'))
65     logger.write(msg)
66     res_source = runner.source(args_source)
67     
68     # Construct the option to pass to the patch command
69     args_patch = args_source.replace(' --force', '')
70     
71     # Call the source command that gets the source
72     msg = src.printcolors.printcHeader(
73                     _('\nApply the patches to the sources of the modules\n'))
74     logger.write(msg)
75     res_patch = runner.patch(args_patch)
76     
77     return res_source + res_patch