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
24 import src.debug as DBG
27 # Define all possible option for prepare command : sat prepare <options>
28 parser = src.options.Options()
29 parser.add_option('p', 'products', 'list2', 'products',
30 _('Optional: products to prepare. This option accepts a comma separated list.'))
31 parser.add_option('f', 'force', 'boolean', 'force',
32 _("Optional: force to prepare the products in development mode."))
33 parser.add_option('', 'force_patch', 'boolean', 'force_patch',
34 _("Optional: force to apply patch to the products in development mode."))
35 parser.add_option('c', 'complete', 'boolean', 'complete',
36 _("Optional: completion mode, only prepare products not present in SOURCES dir."),
39 def find_products_already_prepared(l_products):
40 '''function that returns the list of products that have an existing source
43 :param l_products List: The list of products to check
44 :return: The list of product configurations that have an existing source
49 for p_name_p_cfg in l_products:
50 __, prod_cfg = p_name_p_cfg
51 if "source_dir" in prod_cfg and os.path.exists(prod_cfg.source_dir):
52 l_res.append(p_name_p_cfg)
55 def find_products_with_patchs(l_products):
56 '''function that returns the list of products that have one or more patches.
58 :param l_products List: The list of products to check
59 :return: The list of product configurations that have one or more patches.
63 for p_name_p_cfg in l_products:
64 __, prod_cfg = p_name_p_cfg
65 l_patchs = src.get_cfg_param(prod_cfg, "patches", [])
67 l_res.append(p_name_p_cfg)
71 '''method that is called when salomeTools is called with --help option.
73 :return: The text to display for the prepare command description.
76 return _("The prepare command gets the sources of "
77 "the application products and apply the patches if there is any."
78 "\n\nexample:\nsat prepare SALOME-master --products KERNEL,GUI")
80 def run(args, runner, logger):
81 '''method that is called when salomeTools is called with prepare parameter.
85 (options, args) = parser.parse_args(args)
87 # check that the command has been called with an application
88 src.check_config_has_application( runner.cfg )
90 # write warning if platform is not declared as supported
91 src.check_platform_is_supported( runner.cfg, logger )
93 products_infos = src.product.get_products_list(options, runner.cfg, logger)
94 # Construct the arguments to pass to the clean, source and patch commands
95 args_appli = runner.cfg.VARS.application + " " # useful whitespace
97 listProd = list(options.products)
98 else: # no product interpeted as all products
99 listProd = [name for name, tmp in products_infos]
101 git_server = src.get_git_server(runner.cfg,logger)
103 if src.check_git_repository_has_non_opensource( runner.cfg, git_server):
104 not_opensource_products = [p for p in products_infos if src.product.product_is_not_opensource(p[1])]
105 listProd = [p for p in listProd if p not in [name for name, tmp in not_opensource_products]]
108 # remove products that are already prepared 'completion mode)
109 pi_already_prepared=find_products_already_prepared(products_infos)
110 l_already_prepared = [i for i, tmp in pi_already_prepared]
111 newList, removedList = removeInList(listProd, l_already_prepared)
113 if len(newList) == 0 and len(removedList) > 0 :
114 msg = "\nAll the products are already installed, do nothing!\n"
115 logger.write(src.printcolors.printcWarning(msg), 1)
117 if len(removedList) > 0 :
118 msg = "\nList of already prepared products that are skipped : %s\n" % ",".join(removedList)
122 args_product_opt = '--products ' + ",".join(listProd)
123 do_source = (len(listProd) > 0)
126 ldev_products = [p for p in products_infos if src.product.product_is_dev(p[1])]
127 newList = listProd # default
128 if not options.force and len(ldev_products) > 0:
129 l_products_not_getted = find_products_already_prepared(ldev_products)
130 listNot = [i for i, tmp in l_products_not_getted]
131 newList, removedList = removeInList(listProd, listNot)
132 if len(removedList) > 0:
134 Do not get the source of the following products in development mode.
135 Use the --force option to overwrite it.
137 msg += "\n%s\n" % ",".join(removedList)
138 logger.write(src.printcolors.printcWarning(msg), 1)
140 args_product_opt_clean = '--products ' + ",".join(newList)
141 do_clean = (len(newList) > 0)
143 newList = listProd # default
144 if not options.force_patch and len(ldev_products) > 0:
145 l_products_with_patchs = find_products_with_patchs(ldev_products)
146 listNot = [i for i, tmp in l_products_with_patchs]
147 newList, removedList = removeInList(listProd, listNot)
148 if len(removedList) > 0:
150 Do not patch the following products in development mode.
151 Use the --force_patch option to overwrite it.
153 msg += "\n%s\n" % ",".join(removedList)
154 logger.write(src.printcolors.printcWarning(msg), 1)
156 args_product_opt_patch = '--products ' + ",".join(newList)
157 do_patch = (len(newList) > 0)
159 # Construct the final commands arguments
160 args_clean = args_appli + args_product_opt_clean + " --sources"
161 args_source = args_appli + args_product_opt
162 args_patch = args_appli + args_product_opt_patch
163 # Initialize the results to a running status
168 # Call the commands using the API
170 msg = _("Clean the source directories ...")
173 res_clean = runner.clean(args_clean, batch=True, verbose = 0, logger_add_link = logger)
175 logger.write('%s\n' % src.printcolors.printc(src.OK_STATUS), 3)
177 logger.write('%s\n' % src.printcolors.printc(src.KO_STATUS), 3)
179 msg = _("Get the sources of the products ...")
181 res_source = runner.source(args_source, logger_add_link = logger)
183 logger.write('%s\n' % src.printcolors.printc(src.OK_STATUS), 5)
185 logger.write('%s\n' % src.printcolors.printc(src.KO_STATUS), 5)
187 msg = _("Patch the product sources (if any) ...")
189 res_patch = runner.patch(args_patch, logger_add_link = logger)
191 logger.write('%s\n' % src.printcolors.printc(src.OK_STATUS), 5)
193 logger.write('%s\n' % src.printcolors.printc(src.KO_STATUS), 5)
195 return res_clean + res_source + res_patch
198 def removeInList(aList, removeList):
199 """Removes elements of removeList list from aList
201 :param aList: (list) The list from which to remove elements
202 :param removeList: (list) The list which contains elements to remove
203 :return: (list, list) (list with elements removed, list of elements removed)
205 res1 = [i for i in aList if i not in removeList]
206 res2 = [i for i in aList if i in removeList]