Skip to content

Commit d422a5a

Browse files
committed
Use notifier api in export
1 parent c686c6c commit d422a5a

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

tools/export/__init__.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,24 @@ def generate_project_files(resources, export_path, target, name, toolchain, ide,
205205
return files, exporter
206206

207207

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):
209226
"""Create a zip file from an exported project.
210227
211228
Positional Parameters:
@@ -215,29 +232,25 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
215232
project_files - a list of extra files to be added to the root of the prefix
216233
directory
217234
"""
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
218239
with zipfile.ZipFile(file_name, "w") as zip_file:
219240
for prj_file in project_files:
220241
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]
235244
for source in to_zip:
236245
if source:
237246
zip_file.write(
238247
source,
239248
join(prefix, loc,
240249
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():
241254
for source in res.lib_builds:
242255
target_dir, _ = splitext(source)
243256
dest = join(prefix, loc,
@@ -248,10 +261,9 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
248261

249262

250263
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):
255267
"""Generates a project file and creates a zip archive if specified
256268
257269
Positional Arguments:
@@ -265,13 +277,9 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
265277
linker_script - path to the linker script for the specified target
266278
notify - function is passed all events, and expected to handle notification
267279
of the user, emit the events to a log, etc.
268-
verbose - assigns the notify function to toolchains print_notify_verbose
269280
name - project name
270281
inc_dirs - additional include directories
271282
jobs - number of threads
272-
silent - silent build - no output
273-
extra_verbose - assigns the notify function to toolchains
274-
print_notify_verbose
275283
config - toolchain's config object
276284
macros - User-defined macros
277285
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,
302310
# Pass all params to the unified prepare_resources()
303311
toolchain = prepare_toolchain(
304312
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,
307314
app_config=app_config)
308315
# The first path will give the name to the library
309316
toolchain.RESPONSE_FILES = False
@@ -349,10 +356,10 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
349356
resource.add(res)
350357
if isinstance(zip_proj, basestring):
351358
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)
353360
else:
354361
zip_export(zip_proj, name, resource_dict,
355-
files + list(exporter.static_files), inc_repos)
362+
files + list(exporter.static_files), inc_repos, notify)
356363
else:
357364
for static_file in exporter.static_files:
358365
if not exists(join(export_path, basename(static_file))):

tools/project.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from tools.utils import print_large_string
2727
from tools.utils import NotSupportedException
2828
from tools.options import extract_profile, list_profiles, extract_mcus
29+
from tools.notifier.term import TerminalNotifier
2930

3031
def setup_project(ide, target, program=None, source_dir=None, build=None, export_path=None):
3132
"""Generate a name, if not provided, and find dependencies
@@ -71,7 +72,7 @@ def setup_project(ide, target, program=None, source_dir=None, build=None, export
7172

7273

7374
def export(target, ide, build=None, src=None, macros=None, project_id=None,
74-
zip_proj=False, build_profile=None, export_path=None, silent=False,
75+
zip_proj=False, build_profile=None, export_path=None, notify=None,
7576
app_config=None):
7677
"""Do an export of a project.
7778
@@ -96,7 +97,7 @@ def export(target, ide, build=None, src=None, macros=None, project_id=None,
9697

9798
return export_project(src, project_dir, target, ide, name=name,
9899
macros=macros, libraries_paths=lib, zip_proj=zip_name,
99-
build_profile=build_profile, silent=silent,
100+
build_profile=build_profile, notify=notify,
100101
app_config=app_config)
101102

102103

@@ -247,6 +248,8 @@ def main():
247248

248249
zip_proj = not bool(options.source_dir)
249250

251+
notify = TerminalNotifier()
252+
250253
if (options.program is None) and (not options.source_dir):
251254
args_error(parser, "one of -p, -n, or --source is required")
252255
exporter, toolchain_name = get_exporter_toolchain(options.ide)
@@ -270,7 +273,7 @@ def main():
270273
src=options.source_dir, macros=options.macros,
271274
project_id=options.program, zip_proj=zip_proj,
272275
build_profile=profile, app_config=options.app_config,
273-
export_path=options.build_dir)
276+
export_path=options.build_dir, notify = notify)
274277
except NotSupportedException as exc:
275278
print("[ERROR] %s" % str(exc))
276279

0 commit comments

Comments
 (0)