From 0b21126e6eefe573b1b328934ff46cd07574f7dd Mon Sep 17 00:00:00 2001 From: Tobias Sterbak Date: Mon, 6 Mar 2023 07:35:07 +0000 Subject: [PATCH] Fix issue with whitespaces in paths --- openandroidinstaller/tooling.py | 29 ++++++++++++++++++++--------- tests/test_tooling.py | 6 +++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/openandroidinstaller/tooling.py b/openandroidinstaller/tooling.py index da438efe..ba126772 100644 --- a/openandroidinstaller/tooling.py +++ b/openandroidinstaller/tooling.py @@ -36,7 +36,10 @@ def run_command( - full_command: str, bin_path: Path, enable_logging: bool = True + full_command: str, + bin_path: Path, + target: Optional[Union[str, Path]] = None, + enable_logging: bool = True, ) -> TerminalResponse: """Run a command with a tool (adb, fastboot, heimdall).""" yield f"${full_command}" @@ -54,6 +57,8 @@ def run_command( si = None if enable_logging: logger.info(f"Run command: {command_list}") + if target: + command_list.append(f"{target}") # run the command with subprocess.Popen( command_list, @@ -119,7 +124,7 @@ def adb_reboot_download(bin_path: Path) -> TerminalResponse: @add_logging("Sideload the target to device with adb.") def adb_sideload(bin_path: Path, target: str) -> TerminalResponse: """Sideload the target to device and return success.""" - for line in run_command(f"adb sideload {target}", bin_path): + for line in run_command("adb sideload", target=target, bin_path=bin_path): yield line @@ -210,9 +215,9 @@ def adb_twrp_wipe_and_install( if (type(line) == bool) and not line: logger.error(f"Wiping {partition} failed.") # TODO: if this fails, a fix can be to just sideload something and then adb reboot - for line in run_command( - f"adb sideload {config_path.parent.joinpath(Path('helper.txt'))}", - bin_path, + for line in adb_sideload( + target=f"{config_path.parent.joinpath(Path('helper.txt'))}", + bin_path=bin_path, ): yield line if (type(line) == bool) and not line: @@ -334,11 +339,15 @@ def fastboot_flash_recovery( """Temporarily, flash custom recovery with fastboot.""" if is_ab: logger.info("Boot custom recovery with fastboot.") - for line in run_command(f"fastboot boot {recovery}", bin_path): + for line in run_command( + "fastboot boot", target=f"{recovery}", bin_path=bin_path + ): yield line else: logger.info("Flash custom recovery with fastboot.") - for line in run_command(f"fastboot flash recovery {recovery}", bin_path): + for line in run_command( + "fastboot flash recovery", target=f"{recovery}", bin_path=bin_path + ): yield line if (type(line) == bool) and not line: logger.error("Flashing recovery failed.") @@ -354,7 +363,9 @@ def fastboot_flash_recovery( def fastboot_flash_boot(bin_path: Path, recovery: str) -> TerminalResponse: """Temporarily, flash custom recovery with fastboot to boot partition.""" logger.info("Flash custom recovery with fastboot.") - for line in run_command(f"fastboot flash boot {recovery}", bin_path): + for line in run_command( + "fastboot flash boot", target="f{recovery}", bin_path=bin_path + ): yield line if (type(line) == bool) and not line: logger.error("Flashing recovery failed.") @@ -376,7 +387,7 @@ def fastboot_flash_boot(bin_path: Path, recovery: str) -> TerminalResponse: def heimdall_flash_recovery(bin_path: Path, recovery: str) -> TerminalResponse: """Temporarily, flash custom recovery with heimdall.""" for line in run_command( - f"heimdall flash --no-reboot --RECOVERY {recovery}", bin_path + "heimdall flash --no-reboot --RECOVERY", target=f"{recovery}", bin_path=bin_path ): yield line diff --git a/tests/test_tooling.py b/tests/test_tooling.py index c2195d67..c66f6e97 100644 --- a/tests/test_tooling.py +++ b/tests/test_tooling.py @@ -16,7 +16,11 @@ from pathlib import Path from subprocess import CalledProcessError -from openandroidinstaller.tooling import adb_reboot, search_device, check_ab_partition +from openandroidinstaller.tooling import ( + adb_reboot, + search_device, + check_ab_partition, +) def test_adb_reboot_success(fp):