Skip to content

Commit

Permalink
bin/bash not found (#443)
Browse files Browse the repository at this point in the history
Resolves #429 

Could you please test this @gluckgluckwasserbauch
  • Loading branch information
tsterbak committed Mar 13, 2024
2 parents f225eed + 67ea0f1 commit 823fc86
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
40 changes: 36 additions & 4 deletions openandroidinstaller/tooling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains functions to deal with tools like adb, fastboot and heimdall."""

# This file is part of OpenAndroidInstaller.
# OpenAndroidInstaller is free software: you can redistribute it and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
Expand All @@ -10,6 +11,7 @@
# If not, see <https://www.gnu.org/licenses/>."""
# Author: Tobias Sterbak
import shlex
from dataclasses import dataclass
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -574,24 +576,49 @@ def heimdall_flash_recovery(bin_path: Path, recovery: str) -> TerminalResponse:
yield line


def search_device(platform: str, bin_path: Path) -> Optional[str]:
@dataclass(frozen=True)
class SearchResult:
"""Result of the device search.
Attributes:
device_code: The device code of the connected device.
msg: Message describing the result.
"""

device_code: str = None
msg: str = None


def search_device(platform: str, bin_path: Path) -> SearchResult:
"""Search for a connected device."""
logger.info(f"Search devices on {platform} with {bin_path}...")
try:
# read device code
if platform in ("linux", "darwin"):
# check if grep is installed and find the right path
try:
grep_command = check_output(["which", "grep"]).decode().strip()
except CalledProcessError:
logger.error(
"Failed to detect a device. Please make sure `grep` is installed."
)
return SearchResult(
msg="Failed to detect a device. Please make sure `grep` is installed."
)
# run the command to get the device code
output = check_output(
[
str(bin_path.joinpath(Path("adb"))),
"shell",
"getprop",
"|",
"grep",
grep_command,
"ro.product.device",
],
stderr=STDOUT,
).decode()
elif platform in ("windows", "win32"):
# run the command to get the device code on windows
output = check_output(
[
str(bin_path.joinpath(Path("adb.exe"))),
Expand All @@ -608,7 +635,12 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
raise Exception(f"Unknown platform {platform}.")
device_code = output.split("[")[-1].strip()[:-1].strip()
logger.info(f"Found device code '{device_code}'")
return device_code
return SearchResult(
device_code=device_code,
msg=f"Found device with device code '{device_code}'.",
)
except CalledProcessError:
logger.error("Failed to detect a device.")
return None
return SearchResult(
msg="Failed to detect a device. Connect to USB and try again."
)
1 change: 1 addition & 0 deletions openandroidinstaller/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This file contains some utility functions."""

# This file is part of OpenAndroidInstaller.
# OpenAndroidInstaller is free software: you can redistribute it and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
Expand Down
32 changes: 17 additions & 15 deletions openandroidinstaller/views/start_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Contains the start view."""

# This file is part of OpenAndroidInstaller.
# OpenAndroidInstaller is free software: you can redistribute it and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
Expand Down Expand Up @@ -30,7 +31,7 @@
from flet_core.buttons import CountinuosRectangleBorder
from loguru import logger
from styles import Markdown, Text
from tooling import search_device
from tooling import search_device, SearchResult
from views import BaseView
from widgets import get_title

Expand Down Expand Up @@ -219,29 +220,30 @@ def search_devices_clicked(self, e):
# search the device
if self.state.test:
# this only happens for testing
device_code = self.state.test_config
result = SearchResult(
device_code=self.state.test_config,
msg=f"Found device with device code '{self.state.test_config}'.",
)
logger.info(
f"Running search in development mode and loading config {device_code}.yaml."
f"Running search in development mode and loading config {result.device_code}.yaml."
)
else:
device_code = search_device(
result = search_device(
platform=self.state.platform, bin_path=self.state.bin_path
)
if device_code:
self.device_name.value = device_code
if result.device_code:
self.device_name.value = result.device_code
self.device_name.color = colors.BLACK
else:
logger.info("No device detected! Connect to USB and try again.")
self.device_name.value = (
"No device detected! Connect to USB and try again."
)
self.device_name.value = result.msg
self.device_name.color = colors.RED

# load the config, if a device is detected
if device_code:
self.device_name.value = device_code
if result.device_code:
self.device_name.value = result.device_code
# load config from file
self.state.load_config(device_code)
self.state.load_config(result.device_code)
if self.state.config:
device_name = self.state.config.metadata.get(
"device_name", "No device name in config."
Expand All @@ -265,13 +267,13 @@ def search_devices_clicked(self, e):
else:
# failed to load config or device is not supported
logger.error(
f"Device with code '{device_code}' is not supported or the config is corrupted. Please check the logs for more information."
f"Device with code '{result.device_code}' is not supported or the config is corrupted. Please check the logs for more information."
)
self.device_name.value = (
f"Device with code '{device_code}' is not supported yet."
f"Device with code '{result.device_code}' is not supported yet."
)
# add request support for device button
request_url = f"https://github.com/openandroidinstaller-dev/openandroidinstaller/issues/new?labels=device&template=device-support-request.yaml&title=Add support for `{device_code}`"
request_url = f"https://github.com/openandroidinstaller-dev/openandroidinstaller/issues/new?labels=device&template=device-support-request.yaml&title=Add support for `{result.device_code}`"
self.device_request_row.controls.append(
ElevatedButton(
"Request support for this device",
Expand Down

0 comments on commit 823fc86

Please sign in to comment.