@@ -142,15 +142,27 @@ def export(target, ide, build=None, src=None, macros=None, project_id=None,
142
142
libraries_paths = lib ,
143
143
zip_proj = zip_name ,
144
144
build_profile = build_profile ,
145
- notify = notify ,
145
+ notify = TerminalNotifier () ,
146
146
app_config = app_config ,
147
147
ignore = ignore
148
148
)
149
149
150
-
151
- def main ():
152
- """Entry point"""
153
- # Parse Options
150
+ def clean (source_dir ):
151
+ if exists (EXPORT_DIR ):
152
+ rmtree (EXPORT_DIR )
153
+ for cls in EXPORTERS .values ():
154
+ try :
155
+ cls .clean (basename (abspath (source_dir [0 ])))
156
+ except (NotImplementedError , IOError , OSError ):
157
+ pass
158
+ for f in list (EXPORTERS .values ())[0 ].CLEAN_FILES :
159
+ try :
160
+ remove (f )
161
+ except (IOError , OSError ):
162
+ pass
163
+
164
+
165
+ def get_args (argv ):
154
166
parser = ArgumentParser ()
155
167
156
168
targetnames = TARGET_NAMES
@@ -221,6 +233,13 @@ def main():
221
233
help = "displays supported matrix of MCUs and IDEs"
222
234
)
223
235
236
+ group .add_argument (
237
+ "--update-packs" ,
238
+ dest = "update_packs" ,
239
+ action = "store_true" ,
240
+ default = False
241
+ )
242
+
224
243
parser .add_argument (
225
244
"-E" ,
226
245
action = "store_true" ,
@@ -264,13 +283,6 @@ def main():
264
283
default = []
265
284
)
266
285
267
- parser .add_argument (
268
- "--update-packs" ,
269
- dest = "update_packs" ,
270
- action = "store_true" ,
271
- default = False
272
- )
273
-
274
286
parser .add_argument (
275
287
"--app-config" ,
276
288
dest = "app_config" ,
@@ -286,92 +298,70 @@ def main():
286
298
"(eg. ./main.cpp)" )
287
299
)
288
300
289
- options = parser .parse_args ()
301
+ return parser .parse_args (argv ), parser
302
+
303
+
304
+ def main ():
305
+ """Entry point"""
306
+ # Parse Options
307
+ options , parser = get_args (sys .argv )
290
308
291
309
# Print available tests in order and exit
292
- if options .list_tests is True :
310
+ if options .list_tests :
293
311
print ('\n ' .join (str (test ) for test in sorted (TEST_MAP .values ())))
294
- sys .exit ()
295
-
296
- # Only prints matrix of supported IDEs
297
- if options .supported_ides :
312
+ elif options .supported_ides :
298
313
if options .supported_ides == "matrix" :
299
314
print_large_string (mcu_ide_matrix ())
300
315
elif options .supported_ides == "ides" :
301
316
print (mcu_ide_list ())
302
- exit (0 )
303
-
304
- # Only prints matrix of supported IDEs
305
- if options .supported_ides_html :
317
+ elif options .supported_ides_html :
306
318
html = mcu_ide_matrix (verbose_html = True )
307
319
with open ("./export/README.md" , "w" ) as readme :
308
320
readme .write ("Exporter IDE/Platform Support\n " )
309
321
readme .write ("-----------------------------------\n " )
310
322
readme .write ("\n " )
311
323
readme .write (html )
312
- exit (0 )
313
-
314
- if options .update_packs :
324
+ elif options .update_packs :
315
325
from tools .arm_pack_manager import Cache
316
326
cache = Cache (True , True )
317
327
cache .cache_everything ()
318
-
319
- # Target
320
- if not options .mcu :
321
- args_error (parser , "argument -m/--mcu is required" )
322
-
323
- # Toolchain
324
- if not options .ide :
325
- args_error (parser , "argument -i is required" )
326
-
327
- # Clean Export Directory
328
- if options .clean :
329
- if exists (EXPORT_DIR ):
330
- rmtree (EXPORT_DIR )
331
-
332
- zip_proj = not bool (options .source_dir )
333
-
334
- notify = TerminalNotifier ()
335
-
336
- ide = resolve_exporter_alias (options .ide )
337
- exporter , toolchain_name = get_exporter_toolchain (ide )
338
- profile = extract_profile (parser , options , toolchain_name , fallback = "debug" )
339
- mcu = extract_mcus (parser , options )[0 ]
340
-
341
- if not exporter .is_target_supported (mcu ):
342
- args_error (parser , "%s not supported by %s" % (mcu , ide ))
343
-
344
- if (options .program is None ) and (not options .source_dir ):
345
- args_error (parser , "one of -p, -n, or --source is required" )
346
-
347
- if options .clean :
348
- for cls in EXPORTERS .values ():
349
- try :
350
- cls .clean (basename (abspath (options .source_dir [0 ])))
351
- except (NotImplementedError , IOError , OSError ):
352
- pass
353
- for f in list (EXPORTERS .values ())[0 ].CLEAN_FILES :
354
- try :
355
- remove (f )
356
- except (IOError , OSError ):
357
- pass
358
- try :
359
- export (
360
- mcu ,
361
- ide ,
362
- build = options .build ,
363
- src = options .source_dir ,
364
- macros = options .macros ,
365
- project_id = options .program ,
366
- zip_proj = zip_proj ,
367
- build_profile = profile ,
368
- app_config = options .app_config ,
369
- export_path = options .build_dir ,
370
- notify = notify ,
371
- ignore = options .ignore
372
- )
373
- except NotSupportedException as exc :
374
- print ("[Not Supported] %s" % str (exc ))
328
+ else :
329
+ # Check required arguments
330
+ if not options .mcu :
331
+ args_error (parser , "argument -m/--mcu is required" )
332
+ if not options .ide :
333
+ args_error (parser , "argument -i is required" )
334
+ if (options .program is None ) and (not options .source_dir ):
335
+ args_error (parser , "one of -p, -n, or --source is required" )
336
+
337
+ if options .clean :
338
+ clean (options .source_dir )
339
+
340
+ ide = resolve_exporter_alias (options .ide )
341
+ exporter , toolchain_name = get_exporter_toolchain (ide )
342
+ profile = extract_profile (parser , options , toolchain_name , fallback = "debug" )
343
+ mcu = extract_mcus (parser , options )[0 ]
344
+ if not exporter .is_target_supported (mcu ):
345
+ args_error (parser , "%s not supported by %s" % (mcu , ide ))
346
+
347
+ try :
348
+ export (
349
+ mcu ,
350
+ ide ,
351
+ build = options .build ,
352
+ src = options .source_dir ,
353
+ macros = options .macros ,
354
+ project_id = options .program ,
355
+ zip_proj = not bool (options .source_dir ),
356
+ build_profile = profile ,
357
+ app_config = options .app_config ,
358
+ export_path = options .build_dir ,
359
+ ignore = options .ignore
360
+ )
361
+ except NotSupportedException as exc :
362
+ args_error (parser , "%s not supported by %s" % (mcu , ide ))
363
+ print ("[Not Supported] %s" % str (exc ))
364
+ exit (0 )
375
365
376
366
if __name__ == "__main__" :
377
367
main ()
0 commit comments