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 ,
@@ -122,7 +127,7 @@ def adb_reboot_download(bin_path: Path) -> TerminalResponse:
122127@add_logging ("Sideload the target to device with adb." )
123128def adb_sideload (bin_path : Path , target : str ) -> TerminalResponse :
124129 """Sideload the target to device and return success."""
125- for line in run_command (f "adb sideload { target } " , bin_path ):
130+ for line in run_command ("adb sideload" , target = target , bin_path = bin_path ):
126131 yield line
127132
128133
@@ -228,9 +233,9 @@ def adb_twrp_wipe_and_install(
228233 if (type (line ) == bool ) and not line :
229234 logger .error (f"Wiping { partition } failed." )
230235 # TODO: if this fails, a fix can be to just sideload something and then adb reboot
231- for line in run_command (
232- f"adb sideload { config_path .parent .joinpath (Path ('helper.txt' ))} " ,
233- bin_path ,
236+ for line in adb_sideload (
237+ target = f" { config_path .parent .joinpath (Path ('helper.txt' ))} " ,
238+ bin_path = bin_path ,
234239 ):
235240 yield line
236241 if (type (line ) == bool ) and not line :
@@ -355,13 +360,17 @@ def fastboot_flash_recovery(
355360 """Temporarily, flash custom recovery with fastboot."""
356361 if is_ab :
357362 logger .info ("Boot custom recovery with fastboot." )
358- for line in run_command (f"fastboot boot { recovery } " , bin_path ):
363+ for line in run_command (
364+ "fastboot boot" , target = f"{ recovery } " , bin_path = bin_path
365+ ):
359366 yield line
360367 for line in adb_wait_for_recovery (bin_path = bin_path ):
361368 yield line
362369 else :
363370 logger .info ("Flash custom recovery with fastboot." )
364- for line in run_command (f"fastboot flash recovery { recovery } " , bin_path ):
371+ for line in run_command (
372+ "fastboot flash recovery" , target = f"{ recovery } " , bin_path = bin_path
373+ ):
365374 yield line
366375 for line in adb_wait_for_recovery (bin_path = bin_path ):
367376 yield line
@@ -381,7 +390,9 @@ def fastboot_flash_recovery(
381390def fastboot_flash_boot (bin_path : Path , recovery : str ) -> TerminalResponse :
382391 """Temporarily, flash custom recovery with fastboot to boot partition."""
383392 logger .info ("Flash custom recovery with fastboot." )
384- for line in run_command (f"fastboot flash boot { recovery } " , bin_path ):
393+ for line in run_command (
394+ "fastboot flash boot" , target = "f{recovery}" , bin_path = bin_path
395+ ):
385396 yield line
386397 if (type (line ) == bool ) and not line :
387398 logger .error ("Flashing recovery failed." )
@@ -415,7 +426,7 @@ def heimdall_wait_for_download_available(bin_path: Path) -> bool:
415426def heimdall_flash_recovery (bin_path : Path , recovery : str ) -> TerminalResponse :
416427 """Temporarily, flash custom recovery with heimdall."""
417428 for line in run_command (
418- f "heimdall flash --no-reboot --RECOVERY { recovery } " , bin_path
429+ "heimdall flash --no-reboot --RECOVERY" , target = f" { recovery } " , bin_path = bin_path
419430 ):
420431 yield line
421432
0 commit comments