@@ -205,7 +205,24 @@ def generate_project_files(resources, export_path, target, name, toolchain, ide,
205
205
return files , exporter
206
206
207
207
208
- def zip_export (file_name , prefix , resources , project_files , inc_repos ):
208
+ def _inner_zip_export (resources , inc_repos ):
209
+ for loc , res in resources .items ():
210
+ to_zip = (
211
+ res .headers + res .s_sources + res .c_sources + \
212
+ res .cpp_sources + res .libraries + res .hex_files + \
213
+ [res .linker_script ] + res .bin_files + res .objects + \
214
+ res .json_files + res .lib_refs + res .lib_builds )
215
+ if inc_repos :
216
+ for directory in res .repo_dirs :
217
+ for root , _ , files in walk (directory ):
218
+ for repo_file in files :
219
+ source = join (root , repo_file )
220
+ to_zip .append (source )
221
+ res .file_basepath [source ] = res .base_path
222
+ to_zip += res .repo_files
223
+ yield loc , to_zip
224
+
225
+ def zip_export (file_name , prefix , resources , project_files , inc_repos , notify ):
209
226
"""Create a zip file from an exported project.
210
227
211
228
Positional Parameters:
@@ -215,29 +232,25 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
215
232
project_files - a list of extra files to be added to the root of the prefix
216
233
directory
217
234
"""
235
+ to_zip_list = list (_inner_zip_export (resources , inc_repos ))
236
+ total_files = sum (len (to_zip ) for _ , to_zip in to_zip_list )
237
+ total_files += len (project_files )
238
+ zipped = 0
218
239
with zipfile .ZipFile (file_name , "w" ) as zip_file :
219
240
for prj_file in project_files :
220
241
zip_file .write (prj_file , join (prefix , basename (prj_file )))
221
- for loc , res in resources .items ():
222
- to_zip = (
223
- res .headers + res .s_sources + res .c_sources + \
224
- res .cpp_sources + res .libraries + res .hex_files + \
225
- [res .linker_script ] + res .bin_files + res .objects + \
226
- res .json_files + res .lib_refs + res .lib_builds )
227
- if inc_repos :
228
- for directory in res .repo_dirs :
229
- for root , _ , files in walk (directory ):
230
- for repo_file in files :
231
- source = join (root , repo_file )
232
- to_zip .append (source )
233
- res .file_basepath [source ] = res .base_path
234
- to_zip += res .repo_files
242
+ for loc , to_zip in to_zip_list :
243
+ res = resources [loc ]
235
244
for source in to_zip :
236
245
if source :
237
246
zip_file .write (
238
247
source ,
239
248
join (prefix , loc ,
240
249
relpath (source , res .file_basepath [source ])))
250
+ notify .progress ("Zipping" , source ,
251
+ 100 * (zipped / total_files ))
252
+ zipped += 1
253
+ for lib , res in resources .items ():
241
254
for source in res .lib_builds :
242
255
target_dir , _ = splitext (source )
243
256
dest = join (prefix , loc ,
@@ -248,10 +261,9 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
248
261
249
262
250
263
def export_project (src_paths , export_path , target , ide , libraries_paths = None ,
251
- linker_script = None , notify = None , verbose = False , name = None ,
252
- inc_dirs = None , jobs = 1 , silent = False , extra_verbose = False ,
253
- config = None , macros = None , zip_proj = None , inc_repos = False ,
254
- build_profile = None , app_config = None ):
264
+ linker_script = None , notify = None , name = None , inc_dirs = None ,
265
+ jobs = 1 , config = None , macros = None , zip_proj = None ,
266
+ inc_repos = False , build_profile = None , app_config = None ):
255
267
"""Generates a project file and creates a zip archive if specified
256
268
257
269
Positional Arguments:
@@ -265,13 +277,9 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
265
277
linker_script - path to the linker script for the specified target
266
278
notify - function is passed all events, and expected to handle notification
267
279
of the user, emit the events to a log, etc.
268
- verbose - assigns the notify function to toolchains print_notify_verbose
269
280
name - project name
270
281
inc_dirs - additional include directories
271
282
jobs - number of threads
272
- silent - silent build - no output
273
- extra_verbose - assigns the notify function to toolchains
274
- print_notify_verbose
275
283
config - toolchain's config object
276
284
macros - User-defined macros
277
285
zip_proj - string name of the zip archive you wish to creat (exclude arg
@@ -302,8 +310,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
302
310
# Pass all params to the unified prepare_resources()
303
311
toolchain = prepare_toolchain (
304
312
paths , "" , target , toolchain_name , macros = macros , jobs = jobs ,
305
- notify = notify , silent = silent , verbose = verbose ,
306
- extra_verbose = extra_verbose , config = config , build_profile = build_profile ,
313
+ notify = notify , config = config , build_profile = build_profile ,
307
314
app_config = app_config )
308
315
# The first path will give the name to the library
309
316
toolchain .RESPONSE_FILES = False
@@ -349,10 +356,10 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
349
356
resource .add (res )
350
357
if isinstance (zip_proj , basestring ):
351
358
zip_export (join (export_path , zip_proj ), name , resource_dict ,
352
- files + list (exporter .static_files ), inc_repos )
359
+ files + list (exporter .static_files ), inc_repos , notify )
353
360
else :
354
361
zip_export (zip_proj , name , resource_dict ,
355
- files + list (exporter .static_files ), inc_repos )
362
+ files + list (exporter .static_files ), inc_repos , notify )
356
363
else :
357
364
for static_file in exporter .static_files :
358
365
if not exists (join (export_path , basename (static_file ))):
0 commit comments