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
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."))
31 def get_modules_list(options, cfg, logger):
32 '''method that gives the module list with their informations from
33 configuration regarding the passed options.
35 :param options Options: The Options instance that stores the commands
37 :param config Config: The global configuration
38 :param logger Logger: The logger instance to use for the display and logging
39 :return: The list of (module name, module_infomrmations).
42 # Get the modules to be prepared, regarding the options
43 if options.modules is None:
44 # No options, get all modules sources
45 modules = cfg.APPLICATION.modules
47 # if option --modules, check that all modules of the command line
48 # are present in the application.
49 modules = options.modules
51 if m not in cfg.APPLICATION.modules:
52 raise src.SatException(_("Module %(module)s "
53 "not defined in application %(application)s") %
54 { 'module': m, 'application': cfg.VARS.application} )
56 # Construct the list of tuple containing
57 # the modules name and their definition
58 modules_infos = src.module.get_modules_infos(modules, cfg)
60 # if the --no_sample option is invoked, suppress the sample modules from
64 lmodules_sample = [m for m in modules_infos if src.module.module_is_sample(m[1])]
66 modules_infos = [m for m in modules_infos if m not in lmodules_sample]
68 if len(lmodules_sample) > 0:
69 logger.write(src.printcolors.printcWarning(_("Ignoring the following sample modules:\n")), 1)
70 for i, module in enumerate(lmodules_sample):
72 if i+1 == len(lmodules_sample):
75 logger.write(module[0] + end_text, 1)
80 '''method that is called when salomeTools is called with --help option.
82 :return: The text to display for the prepare command description.
85 return _("The prepare command apply the patches on the sources of "
86 "the application modules if there is any")
88 def run(args, runner, logger):
89 '''method that is called when salomeTools is called with prepare parameter.
93 (options, args) = parser.parse_args(args)
95 # check that the command has been called with an application
96 src.check_config_has_application( runner.cfg )
98 modules_infos = get_modules_list(options, runner.cfg, logger)
100 # Construct the option to pass to the source command
101 args_source = runner.cfg.VARS.application + ' '
104 args_source += '--module ' + ','.join(options.modules)
106 if options.no_sample:
107 args_source += ' --no_sample'
110 args_source += ' --force'
112 # Call the source command that gets the source
113 msg = src.printcolors.printcHeader(
114 _('Get the sources of the desired modules\n'))
116 res_source = runner.source(args_source)
118 # Construct the option to pass to the patch command
119 args_patch = args_source.replace(' --force', '')
121 if ("dev_modules" in runner.cfg.APPLICATION and
122 runner.cfg.APPLICATION.dev_modules is not []):
124 dev_modules = runner.cfg.APPLICATION.dev_modules
125 ldev_modules = [m for m in modules_infos if m[0] in dev_modules]
127 if len(ldev_modules) > 0:
128 msg = _("The patches are not applied on "
129 "the module in development mode\n")
133 modules_infos = [m for m in modules_infos if m[0] not in ldev_modules]
135 # Call the source command that gets the source
136 msg = src.printcolors.printcHeader(
137 _('\nApply the patches to the sources of the modules\n'))
139 res_patch = runner.patch(args_patch)
141 return res_source + res_patch