Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with whitespaces in paths #95

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions openandroidinstaller/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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,
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.")
Expand All @@ -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.")
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion tests/test_tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down