@@ -163,7 +163,24 @@ def generate_project_files(resources, export_path, target, name, toolchain, ide,
163
163
return files , exporter
164
164
165
165
166
- def zip_export (file_name , prefix , resources , project_files , inc_repos ):
166
+ def _inner_zip_export (resources , inc_repos ):
167
+ for loc , res in resources .items ():
168
+ to_zip = (
169
+ res .headers + res .s_sources + res .c_sources + \
170
+ res .cpp_sources + res .libraries + res .hex_files + \
171
+ [res .linker_script ] + res .bin_files + res .objects + \
172
+ res .json_files + res .lib_refs + res .lib_builds )
173
+ if inc_repos :
174
+ for directory in res .repo_dirs :
175
+ for root , _ , files in walk (directory ):
176
+ for repo_file in files :
177
+ source = join (root , repo_file )
178
+ to_zip .append (source )
179
+ res .file_basepath [source ] = res .base_path
180
+ to_zip += res .repo_files
181
+ yield loc , to_zip
182
+
183
+ def zip_export (file_name , prefix , resources , project_files , inc_repos , notify ):
167
184
"""Create a zip file from an exported project.
168
185
169
186
Positional Parameters:
@@ -173,29 +190,25 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
173
190
project_files - a list of extra files to be added to the root of the prefix
174
191
directory
175
192
"""
193
+ to_zip_list = list (_inner_zip_export (resources , inc_repos ))
194
+ total_files = sum (len (to_zip ) for _ , to_zip in to_zip_list )
195
+ total_files += len (project_files )
196
+ zipped = 0
176
197
with zipfile .ZipFile (file_name , "w" ) as zip_file :
177
198
for prj_file in project_files :
178
199
zip_file .write (prj_file , join (prefix , basename (prj_file )))
179
- for loc , res in resources .items ():
180
- to_zip = (
181
- res .headers + res .s_sources + res .c_sources + \
182
- res .cpp_sources + res .libraries + res .hex_files + \
183
- [res .linker_script ] + res .bin_files + res .objects + \
184
- res .json_files + res .lib_refs + res .lib_builds )
185
- if inc_repos :
186
- for directory in res .repo_dirs :
187
- for root , _ , files in walk (directory ):
188
- for repo_file in files :
189
- source = join (root , repo_file )
190
- to_zip .append (source )
191
- res .file_basepath [source ] = res .base_path
192
- to_zip += res .repo_files
200
+ for loc , to_zip in to_zip_list :
201
+ res = resources [loc ]
193
202
for source in to_zip :
194
203
if source :
195
204
zip_file .write (
196
205
source ,
197
206
join (prefix , loc ,
198
207
relpath (source , res .file_basepath [source ])))
208
+ notify .progress ("Zipping" , source ,
209
+ 100 * (zipped / total_files ))
210
+ zipped += 1
211
+ for lib , res in resources .items ():
199
212
for source in res .lib_builds :
200
213
target_dir , _ = splitext (source )
201
214
dest = join (prefix , loc ,
@@ -206,10 +219,9 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
206
219
207
220
208
221
def export_project (src_paths , export_path , target , ide , libraries_paths = None ,
209
- linker_script = None , notify = None , verbose = False , name = None ,
210
- inc_dirs = None , jobs = 1 , silent = False , extra_verbose = False ,
211
- config = None , macros = None , zip_proj = None , inc_repos = False ,
212
- build_profile = None , app_config = None ):
222
+ linker_script = None , notify = None , name = None , inc_dirs = None ,
223
+ jobs = 1 , config = None , macros = None , zip_proj = None ,
224
+ inc_repos = False , build_profile = None , app_config = None ):
213
225
"""Generates a project file and creates a zip archive if specified
214
226
215
227
Positional Arguments:
@@ -223,13 +235,9 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
223
235
linker_script - path to the linker script for the specified target
224
236
notify - function is passed all events, and expected to handle notification
225
237
of the user, emit the events to a log, etc.
226
- verbose - assigns the notify function to toolchains print_notify_verbose
227
238
name - project name
228
239
inc_dirs - additional include directories
229
240
jobs - number of threads
230
- silent - silent build - no output
231
- extra_verbose - assigns the notify function to toolchains
232
- print_notify_verbose
233
241
config - toolchain's config object
234
242
macros - User-defined macros
235
243
zip_proj - string name of the zip archive you wish to creat (exclude arg
@@ -260,8 +268,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
260
268
# Pass all params to the unified prepare_resources()
261
269
toolchain = prepare_toolchain (
262
270
paths , "" , target , toolchain_name , macros = macros , jobs = jobs ,
263
- notify = notify , silent = silent , verbose = verbose ,
264
- extra_verbose = extra_verbose , config = config , build_profile = build_profile ,
271
+ notify = notify , config = config , build_profile = build_profile ,
265
272
app_config = app_config )
266
273
267
274
toolchain .RESPONSE_FILES = False
@@ -300,10 +307,10 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
300
307
resource .add (res )
301
308
if isinstance (zip_proj , basestring ):
302
309
zip_export (join (export_path , zip_proj ), name , resource_dict ,
303
- files + list (exporter .static_files ), inc_repos )
310
+ files + list (exporter .static_files ), inc_repos , notify )
304
311
else :
305
312
zip_export (zip_proj , name , resource_dict ,
306
- files + list (exporter .static_files ), inc_repos )
313
+ files + list (exporter .static_files ), inc_repos , notify )
307
314
else :
308
315
for static_file in exporter .static_files :
309
316
if not exists (join (export_path , basename (static_file ))):
0 commit comments