55'''Runner for flashing with nrfutil.'''
66
77import json
8+ import shlex
89import subprocess
910import sys
1011from pathlib import Path
@@ -18,12 +19,12 @@ class NrfUtilBinaryRunner(NrfBinaryRunner):
1819
1920 def __init__ (self , cfg , family , softreset , pinreset , dev_id , erase = False ,
2021 erase_mode = None , ext_erase_mode = None , reset = True , tool_opt = None ,
21- force = False , recover = False ,
22- ext_mem_config_file = None ):
22+ force = False , recover = False , ext_mem_config_file = None ,
23+ dry_run = False ):
2324
2425 super ().__init__ (cfg , family , softreset , pinreset , dev_id , erase ,
2526 erase_mode , ext_erase_mode , reset , tool_opt , force ,
26- recover )
27+ recover , dry_run )
2728
2829 self .ext_mem_config_file = ext_mem_config_file
2930
@@ -55,23 +56,32 @@ def do_create(cls, cfg, args):
5556 ext_erase_mode = args .ext_erase_mode ,
5657 reset = args .reset , tool_opt = args .tool_opt ,
5758 force = args .force , recover = args .recover ,
58- ext_mem_config_file = args .ext_mem_config_file )
59+ ext_mem_config_file = args .ext_mem_config_file ,
60+ dry_run = args .dry_run )
5961
6062 @classmethod
6163 def do_add_parser (cls , parser ):
6264 super ().do_add_parser (parser )
6365 parser .add_argument ('--ext-mem-config-file' , required = False ,
6466 dest = 'ext_mem_config_file' ,
6567 help = 'path to an JSON file with external memory configuration' )
68+ parser .add_argument ('--dry-run' , required = False ,
69+ action = 'store_true' ,
70+ help = '''Generate all the commands without actually
71+ executing them''' )
6672
67- def _exec (self , args ):
73+ def _exec (self , args , force = False ):
6874 jout_all = []
6975
7076 cmd = ['nrfutil' , '--json' , 'device' ] + args
71- self ._log_cmd (cmd )
7277
73- if _DRY_RUN :
74- return {}
78+ escaped = ' ' .join (shlex .quote (s ) for s in cmd )
79+ if _DRY_RUN or (self .dry_run ):
80+ self .logger .info (escaped )
81+ if not force :
82+ return {}
83+ else :
84+ self .logger .debug (escaped )
7585
7686 with subprocess .Popen (cmd , stdout = subprocess .PIPE ) as p :
7787 for line in iter (p .stdout .readline , b'' ):
@@ -148,7 +158,7 @@ def _append_batch(self, op, json_file):
148158 cmd += ['--core' , op ['core' ]] if op .get ('core' ) else []
149159 cmd += ['--x-family' , f'{ self .family } ' ]
150160 cmd += ['--x-append-batch' , f'{ json_file } ' ]
151- self ._exec (cmd )
161+ self ._exec (cmd , force = True )
152162
153163 def _exec_batch (self ):
154164 # Use x-append-batch to get the JSON from nrfutil itself
0 commit comments