136 "the given regular expression. Matching is case-insensitive. "\ |
136 "the given regular expression. Matching is case-insensitive. "\ |
137 "Example --exclude-content-filter=\".*\.sisx|.*\.sis|.*\.wgz|.*wgt\" "\ |
137 "Example --exclude-content-filter=\".*\.sisx|.*\.sis|.*\.wgz|.*wgt\" "\ |
138 "Filters out all files with extension sis, sisx, wgz or wgt.", |
138 "Filters out all files with extension sis, sisx, wgz or wgt.", |
139 default=None) |
139 default=None) |
140 |
140 |
|
141 group.add_option("--include-content-filter", |
|
142 dest="include_content_filter", |
|
143 help="Filters out files and folders from content folder which don't match with "\ |
|
144 "the given regular expression. Matching is case-insensitive. "\ |
|
145 "Example --include-content-filter=\".*(manual|configurator).*\" "\ |
|
146 "Filters out all content files which don't have manual or configurator in their path.", |
|
147 default=None) |
|
148 |
141 |
149 |
142 parser.add_option_group(group) |
150 parser.add_option_group(group) |
143 (options, args) = parser.parse_args() |
151 (options, args) = parser.parse_args() |
144 |
152 |
145 cone_common.handle_common_options(options) |
153 cone_common.handle_common_options(options) |
199 export_format = options.export_format or 'cpf', |
207 export_format = options.export_format or 'cpf', |
200 configs = config_list, |
208 configs = config_list, |
201 added_layers = options.added, |
209 added_layers = options.added, |
202 empty_folders = not options.exclude_empty_folders, |
210 empty_folders = not options.exclude_empty_folders, |
203 exclude_filters = {"content": options.exclude_content_filter}, |
211 exclude_filters = {"content": options.exclude_content_filter}, |
|
212 include_filters = {"content": options.include_content_filter}, |
204 options = options) |
213 options = options) |
205 else: |
214 else: |
206 _export_to_storage(project = project, |
215 _export_to_storage(project = project, |
207 remote_project_location = options.remote, |
216 remote_project_location = options.remote, |
208 configs = config_list, |
217 configs = config_list, |
209 added_layers = options.added, |
218 added_layers = options.added, |
210 empty_folders = not options.exclude_empty_folders, |
219 empty_folders = not options.exclude_empty_folders, |
211 exclude_filters = {"content": options.exclude_content_filter}, |
220 exclude_filters = {"content": options.exclude_content_filter}, |
|
221 include_filters = {"content": options.include_content_filter}, |
212 options = options) |
222 options = options) |
213 |
223 |
214 |
224 |
215 def _export_to_storage(project, remote_project_location, configs, added_layers, empty_folders, exclude_filters, options): |
225 def _export_to_storage(project, remote_project_location, configs, added_layers, empty_folders, exclude_filters, include_filters, options): |
216 assert len(configs) > 0 |
226 assert len(configs) > 0 |
217 |
227 |
218 # If the remote storage is not given, determine it automatically based |
228 # If the remote storage is not given, determine it automatically based |
219 # on the first specified configuration name |
229 # on the first specified configuration name |
220 if not remote_project_location: |
230 if not remote_project_location: |
238 except Exception,e: |
248 except Exception,e: |
239 logger.warning('Running plugin %s threw an exception: %s' % (action_name, e)) |
249 logger.warning('Running plugin %s threw an exception: %s' % (action_name, e)) |
240 project.export_configuration(config, |
250 project.export_configuration(config, |
241 remote_project.storage, |
251 remote_project.storage, |
242 empty_folders = empty_folders, |
252 empty_folders = empty_folders, |
243 exclude_filters = exclude_filters) |
253 exclude_filters = exclude_filters, |
|
254 include_filters = include_filters) |
244 print "Export %s to %s done!" % (config_path, remote_project_location) |
255 print "Export %s to %s done!" % (config_path, remote_project_location) |
245 |
256 |
246 # Setting first as active configuration if there are more than one configuration defined. |
257 # Setting first as active configuration if there are more than one configuration defined. |
247 configs = remote_project.list_configurations() |
258 configs = remote_project.list_configurations() |
248 if len(configs): |
259 if len(configs): |
252 pass |
263 pass |
253 |
264 |
254 remote_project.save() |
265 remote_project.save() |
255 remote_project.close() |
266 remote_project.close() |
256 |
267 |
257 _add_layers(project, remote_project_location, added_layers, empty_folders, exclude_filters, options) |
268 _add_layers(project, remote_project_location, added_layers, empty_folders, exclude_filters, include_filters, options) |
258 |
269 |
259 def _add_layers(source_project, remote_project_location, added_configs, empty_folders, exclude_filters, options): |
270 def _add_layers(source_project, remote_project_location, added_configs, empty_folders, exclude_filters, include_filters, options): |
260 """ |
271 """ |
261 Add new configuration layers from source_project into |
272 Add new configuration layers from source_project into |
262 """ |
273 """ |
263 if not added_configs: |
274 if not added_configs: |
264 return |
275 return |
276 # The configuration exists in the source project, export it from there |
287 # The configuration exists in the source project, export it from there |
277 existing_config = source_project.get_configuration(added_config_name) |
288 existing_config = source_project.get_configuration(added_config_name) |
278 source_project.export_configuration(existing_config, |
289 source_project.export_configuration(existing_config, |
279 target_project.storage, |
290 target_project.storage, |
280 empty_folders = empty_folders, |
291 empty_folders = empty_folders, |
281 exclude_filters = exclude_filters) |
292 exclude_filters = exclude_filters, |
|
293 include_filters = include_filters) |
282 else: |
294 else: |
283 # The given configuration does not exist in the source project, |
295 # The given configuration does not exist in the source project, |
284 # create a new empty layer |
296 # create a new empty layer |
285 logger.info("Creating new layer %s." % added_config_name) |
297 logger.info("Creating new layer %s." % added_config_name) |
286 new_config = target_project.create_configuration(added_config_name) |
298 new_config = target_project.create_configuration(added_config_name) |
290 target_config.include_configuration(utils.resourceref.norm(added_config_name)) |
302 target_config.include_configuration(utils.resourceref.norm(added_config_name)) |
291 |
303 |
292 target_project.save() |
304 target_project.save() |
293 target_project.close() |
305 target_project.close() |
294 |
306 |
295 def _export_to_dir(project, export_dir, export_format, configs, added_layers, empty_folders, exclude_filters, options): |
307 def _export_to_dir(project, export_dir, export_format, configs, added_layers, empty_folders, exclude_filters, include_filters, options): |
296 if not os.path.exists(export_dir): |
308 if not os.path.exists(export_dir): |
297 os.makedirs(export_dir) |
309 os.makedirs(export_dir) |
298 |
310 |
299 for config in configs: |
311 for config in configs: |
300 remote_name, _ = os.path.splitext(os.path.basename(config)) |
312 remote_name, _ = os.path.splitext(os.path.basename(config)) |
302 remote_name += '.cpf' |
314 remote_name += '.cpf' |
303 elif export_format.lower() == 'dir': |
315 elif export_format.lower() == 'dir': |
304 remote_name += '/' |
316 remote_name += '/' |
305 |
317 |
306 remote_name = os.path.join(export_dir, remote_name) |
318 remote_name = os.path.join(export_dir, remote_name) |
307 _export_to_storage(project, remote_name, [config], added_layers, empty_folders, exclude_filters, options) |
319 _export_to_storage(project, remote_name, [config], added_layers, empty_folders, exclude_filters, include_filters, options) |
308 |
320 |
309 if __name__ == "__main__": |
321 if __name__ == "__main__": |
310 main() |
322 main() |