3636
3737
3838def run_command (
39- full_command : str , bin_path : Path , enable_logging : bool = True
39+ full_command : str ,
40+ bin_path : Path ,
41+ target : Optional [Union [str , Path ]] = None ,
42+ enable_logging : bool = True ,
4043) -> TerminalResponse :
4144 """Run a command with a tool (adb, fastboot, heimdall)."""
4245 yield f"${ full_command } "
@@ -54,6 +57,8 @@ def run_command(
5457 si = None
5558 if enable_logging :
5659 logger .info (f"Run command: { command_list } " )
60+ if target :
61+ command_list .append (f"{ target } " )
5762 # run the command
5863 with subprocess .Popen (
5964 command_list ,
@@ -119,7 +124,7 @@ def adb_reboot_download(bin_path: Path) -> TerminalResponse:
119124@add_logging ("Sideload the target to device with adb." )
120125def adb_sideload (bin_path : Path , target : str ) -> TerminalResponse :
121126 """Sideload the target to device and return success."""
122- for line in run_command (f "adb sideload { target } " , bin_path ):
127+ for line in run_command ("adb sideload" , target = target , bin_path = bin_path ):
123128 yield line
124129
125130
@@ -210,9 +215,9 @@ def adb_twrp_wipe_and_install(
210215 if (type (line ) == bool ) and not line :
211216 logger .error (f"Wiping { partition } failed." )
212217 # TODO: if this fails, a fix can be to just sideload something and then adb reboot
213- for line in run_command (
214- f"adb sideload { config_path .parent .joinpath (Path ('helper.txt' ))} " ,
215- bin_path ,
218+ for line in adb_sideload (
219+ target = f" { config_path .parent .joinpath (Path ('helper.txt' ))} " ,
220+ bin_path = bin_path ,
216221 ):
217222 yield line
218223 if (type (line ) == bool ) and not line :
@@ -334,11 +339,15 @@ def fastboot_flash_recovery(
334339 """Temporarily, flash custom recovery with fastboot."""
335340 if is_ab :
336341 logger .info ("Boot custom recovery with fastboot." )
337- for line in run_command (f"fastboot boot { recovery } " , bin_path ):
342+ for line in run_command (
343+ "fastboot boot" , target = f"{ recovery } " , bin_path = bin_path
344+ ):
338345 yield line
339346 else :
340347 logger .info ("Flash custom recovery with fastboot." )
341- for line in run_command (f"fastboot flash recovery { recovery } " , bin_path ):
348+ for line in run_command (
349+ "fastboot flash recovery" , target = f"{ recovery } " , bin_path = bin_path
350+ ):
342351 yield line
343352 if (type (line ) == bool ) and not line :
344353 logger .error ("Flashing recovery failed." )
@@ -354,7 +363,9 @@ def fastboot_flash_recovery(
354363def fastboot_flash_boot (bin_path : Path , recovery : str ) -> TerminalResponse :
355364 """Temporarily, flash custom recovery with fastboot to boot partition."""
356365 logger .info ("Flash custom recovery with fastboot." )
357- for line in run_command (f"fastboot flash boot { recovery } " , bin_path ):
366+ for line in run_command (
367+ "fastboot flash boot" , target = "f{recovery}" , bin_path = bin_path
368+ ):
358369 yield line
359370 if (type (line ) == bool ) and not line :
360371 logger .error ("Flashing recovery failed." )
@@ -376,7 +387,7 @@ def fastboot_flash_boot(bin_path: Path, recovery: str) -> TerminalResponse:
376387def heimdall_flash_recovery (bin_path : Path , recovery : str ) -> TerminalResponse :
377388 """Temporarily, flash custom recovery with heimdall."""
378389 for line in run_command (
379- f "heimdall flash --no-reboot --RECOVERY { recovery } " , bin_path
390+ "heimdall flash --no-reboot --RECOVERY" , target = f" { recovery } " , bin_path = bin_path
380391 ):
381392 yield line
382393
0 commit comments