]> SALOME platform Git repositories - tools/sat.git/blob - commands/prepare.py
Salome HOME
See redhat as CentOS
[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('p', 'product', 'list2', 'products',
24     _('products to prepare. This option can be'
25     ' passed several time to prepare several products.'))
26 parser.add_option('', 'no_sample', 'boolean', 'no_sample', 
27     _("do not prepare sample products."))
28 parser.add_option('f', 'force', 'boolean', 'force', 
29     _("force to prepare the products in development mode."))
30 parser.add_option('f', 'force_patch', 'boolean', 'force_patch', 
31     _("force to apply patch to the products in development mode."))
32
33 def get_products_list(options, cfg, logger):
34     '''method that gives the product list with their informations from 
35        configuration regarding the passed options.
36     
37     :param options Options: The Options instance that stores the commands 
38                             arguments
39     :param config Config: The global configuration
40     :param logger Logger: The logger instance to use for the display and logging
41     :return: The list of (product name, product_informations).
42     :rtype: List
43     '''
44     # Get the products to be prepared, regarding the options
45     if options.products is None:
46         # No options, get all products sources
47         products = cfg.APPLICATION.products
48     else:
49         # if option --products, check that all products of the command line
50         # are present in the application.
51         products = options.products
52         for p in products:
53             if p not in cfg.APPLICATION.products:
54                 raise src.SatException(_("Product %(product)s "
55                             "not defined in application %(application)s") %
56                 { 'product': p, 'application': cfg.VARS.application} )
57     
58     # Construct the list of tuple containing 
59     # the products name and their definition
60     products_infos = src.product.get_products_infos(products, cfg)
61
62     # if the --no_sample option is invoked, suppress the sample products from 
63     # the list
64     if options.no_sample:
65         
66         lproducts_sample = [p for p in products_infos if src.product.product_is_sample(p[1])]
67         
68         products_infos = [p for p in products_infos if p not in lproducts_sample]
69
70         if len(lproducts_sample) > 0:
71             msg = "Ignoring the following sample products:\n"
72             logger.write(src.printcolors.printcWarning(_(msg)), 1)
73         for i, product in enumerate(lproducts_sample):
74             end_text = ', '
75             if i+1 == len(lproducts_sample):
76                 end_text = '\n'
77                 
78             logger.write(product[0] + end_text, 1)
79     
80     return products_infos
81
82 def description():
83     '''method that is called when salomeTools is called with --help option.
84     
85     :return: The text to display for the prepare command description.
86     :rtype: str
87     '''
88     return _("The prepare command gets the sources of "
89              "the application products and apply the patches if there is any.")
90   
91 def run(args, runner, logger):
92     '''method that is called when salomeTools is called with prepare parameter.
93     '''
94     
95     # Parse the options
96     (options, args) = parser.parse_args(args)
97
98     # check that the command has been called with an application
99     src.check_config_has_application( runner.cfg )
100
101     products_infos = get_products_list(options, runner.cfg, logger)
102
103     ##################################
104     ## Source command
105
106     # Construct the option to pass to the source command
107     args_appli = runner.cfg.VARS.application + ' '
108
109     args_product_opt = '--product '
110     if options.products:
111         for p_name in options.products:
112             args_product_opt += ',' + p_name
113     else:
114         for p_name, __ in products_infos:
115             args_product_opt += ',' + p_name
116     
117     args_sample = ''
118     if options.no_sample:
119         args_sample = ' --no_sample'
120     
121     args_source = args_appli + args_product_opt + args_sample
122         
123     if options.force:
124         args_source += ' --force'
125     
126     # Call the source command that gets the source
127     msg = src.printcolors.printcHeader(
128                                 _('Get the sources of the desired products\n'))
129     logger.write(msg)
130     res_source = runner.source(args_source)
131     
132     
133     ##################################
134     ## Patch command
135     msg = src.printcolors.printcHeader(
136                     _('\nApply the patches to the sources of the products\n'))
137     logger.write(msg)
138
139     # Construct the option to pass to the patch command
140     ldev_products = [p for p in products_infos if src.product.product_is_dev(p[1])]
141     if len(ldev_products) > 0 and not options.force_patch:
142         msg = _("Ignoring the following products "
143                 "in development mode\n")
144         logger.write(src.printcolors.printcWarning(msg), 1)
145         for i, (product_name, __) in enumerate(ldev_products):
146             args_product_opt = args_product_opt.replace(',' + product_name, '')
147             end_text = ', '
148             if i+1 == len(ldev_products):
149                 end_text = '\n'
150                 
151             logger.write(product_name + end_text, 1)
152         
153         msg = _("Use the --force_patch option to apply the patches anyway\n\n")
154         logger.write(src.printcolors.printcWarning(msg), 1)
155             
156     if args_product_opt == '--product ':
157         msg = _("Nothing to patch\n")
158         logger.write(msg)
159         res_patch = 0
160     else:
161         args_patch = args_appli + args_product_opt + args_sample
162         
163         # Call the source command that gets the source
164         res_patch = runner.patch(args_patch)
165     
166     return res_source + res_patch