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
23 # Define all possible option for prepare command : sat prepare <options>
24 parser = src.options.Options()
25 parser.add_option('p', 'products', 'list2', 'products',
26 _('products to prepare. This option can be'
27 ' passed several time to prepare several 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."))
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.
37 :param options Options: The Options instance that stores the commands
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).
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
49 # if option --products, check that all products of the command line
50 # are present in the application.
51 products = options.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} )
58 # Construct the list of tuple containing
59 # the products name and their definition
60 products_infos = src.product.get_products_infos(products, cfg)
64 def remove_products(arguments, l_products_info, logger):
65 '''method that removes the products in l_products_info from arguments list.
67 :param arguments str: The arguments from which to remove products
68 :param l_products_info list: List of
69 (str, Config) => (product_name, product_info)
70 :param logger Logger: The logger instance to use for the display and logging
71 :return: The updated arguments.
75 for i, (product_name, __) in enumerate(l_products_info):
76 args = args.replace(',' + product_name, '')
78 if i+1 == len(l_products_info):
80 logger.write(product_name + end_text, 1)
84 '''method that is called when salomeTools is called with --help option.
86 :return: The text to display for the prepare command description.
89 return _("The prepare command gets the sources of "
90 "the application products and apply the patches if there is any.")
92 def run(args, runner, logger):
93 '''method that is called when salomeTools is called with prepare parameter.
97 (options, args) = parser.parse_args(args)
99 # check that the command has been called with an application
100 src.check_config_has_application( runner.cfg )
102 products_infos = get_products_list(options, runner.cfg, logger)
104 # Construct the arguments to pass to the clean, source and patch commands
105 args_appli = runner.cfg.VARS.application + ' '
106 args_product_opt = '--products '
108 for p_name in options.products:
109 args_product_opt += ',' + p_name
111 for p_name, __ in products_infos:
112 args_product_opt += ',' + p_name
114 ldev_products = [p for p in products_infos if src.product.product_is_dev(p[1])]
115 args_product_opt_clean = args_product_opt
116 if not options.force and len(ldev_products) > 0:
117 msg = _("Do not get the source of the following products "
118 "in development mode\nUse the --force option to"
120 logger.write(src.printcolors.printcWarning(msg), 1)
121 args_product_opt_clean = remove_products(args_product_opt_clean,
124 logger.write("\n", 1)
127 args_product_opt_patch = args_product_opt
128 if not options.force_patch and len(ldev_products) > 0:
129 msg = _("do not patch the following products "
130 "in development mode\nUse the --force_patch option to"
132 logger.write(src.printcolors.printcWarning(msg), 1)
133 args_product_opt_patch = remove_products(args_product_opt_patch,
136 logger.write("\n", 1)
138 # Construct the final commands arguments
139 args_clean = args_appli + args_product_opt_clean + " --sources"
140 args_source = args_appli + args_product_opt
141 args_patch = args_appli + args_product_opt_patch
143 # If there is no more any product in the command arguments,
144 # do not call the concerned command
145 oExpr = re.compile("^--products *$")
146 do_clean = not(oExpr.search(args_product_opt_clean))
147 do_source = not(oExpr.search(args_product_opt))
148 do_patch = not(oExpr.search(args_product_opt_patch))
151 # Initialize the results to a failing status
156 # Call the commands using the API
158 msg = _("Clean the source directories ...")
160 res_clean = runner.clean(args_clean, batch=True, verbose = 0)
162 logger.write('%s\n\n' % src.printcolors.printc(src.OK_STATUS), 3)
164 res_source = runner.source(args_source)
166 res_patch = runner.patch(args_patch)
168 return res_clean + res_source + res_patch