Skip to content

Commit a4d13d4

Browse files
committed
Format and lint
1 parent 6ec588d commit a4d13d4

7 files changed

Lines changed: 85 additions & 61 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ install:
88
export:
99
poetry export -f requirements.txt --output requirements.txt
1010

11+
lint:
12+
poetry run ruff openandroidinstaller/ --ignore E501
13+
1114
test:
1215
poetry run pytest tests/
1316

openandroidinstaller/app_state.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from flet import ProgressBar
1919
from installer_config import _load_config
20-
from loguru import logger
2120

2221

2322
class AppState:

openandroidinstaller/openandroidinstaller.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
import sys
1818
import webbrowser
1919
from pathlib import Path
20-
from time import sleep
21-
from typing import Callable, Optional
2220

2321
import flet
24-
import regex as re
2522
from app_state import AppState
2623
from flet import (
2724
AppBar,
@@ -40,15 +37,14 @@
4037
colors,
4138
icons,
4239
)
43-
from installer_config import Step
4440
from loguru import logger
4541
from views import SelectFilesView, StepView, SuccessView, WelcomeView
4642

4743
# where to write the logs
4844
logger.add("openandroidinstaller.log")
4945

5046
# Toggle to True for development purposes
51-
DEVELOPMENT = False
47+
DEVELOPMENT = False
5248
DEVELOPMENT_CONFIG = "yuga" # "a3y17lte" # "sargo"
5349

5450

@@ -137,7 +133,7 @@ def main(page: Page):
137133
# header
138134
page.appbar = AppBar(
139135
leading=Image(
140-
src=f"/assets/logo-192x192.png", height=40, width=40, border_radius=40
136+
src="/assets/logo-192x192.png", height=40, width=40, border_radius=40
141137
),
142138
leading_width=56,
143139
toolbar_height=72,

openandroidinstaller/tool_utils.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
CalledProcessError,
2323
CompletedProcess,
2424
check_output,
25-
run,
2625
)
2726
from time import sleep
2827
from typing import List, Optional
2928

30-
import regex as re
3129
from loguru import logger
3230

3331
PLATFORM = sys.platform
@@ -43,7 +41,9 @@ def run_command(tool: str, command: List[str], bin_path: Path) -> CompletedProce
4341
else:
4442
full_command = [str(bin_path.joinpath(Path(f"{tool}")))] + command
4543
logger.info(f"Run command: {full_command}")
46-
with Popen(full_command, stdout=PIPE, stderr=STDOUT, bufsize=1, universal_newlines=True) as p:
44+
with Popen(
45+
full_command, stdout=PIPE, stderr=STDOUT, bufsize=1, universal_newlines=True
46+
) as p:
4747
for line in p.stdout:
4848
logger.info(line.strip())
4949
yield line
@@ -59,7 +59,7 @@ def adb_reboot(bin_path: Path) -> bool:
5959
if (type(line) == bool) and line:
6060
logger.debug("Reboot failed.")
6161
yield False
62-
else:
62+
else:
6363
yield True
6464

6565

@@ -71,7 +71,7 @@ def adb_reboot_bootloader(bin_path: Path) -> bool:
7171
if (type(line) == bool) and not line:
7272
logger.error("Reboot into bootloader failed.")
7373
yield False
74-
return
74+
return
7575
sleep(1)
7676
yield True
7777
# TODO: check if in fastboot mode
@@ -92,7 +92,7 @@ def adb_reboot_download(bin_path: Path) -> bool:
9292
if (type(line) == bool) and not line:
9393
logger.error("Reboot into download mode failed.")
9494
yield False
95-
else:
95+
else:
9696
# check if in download mode with heimdall?
9797
yield True
9898

@@ -105,7 +105,7 @@ def adb_sideload(bin_path: Path, target: str) -> bool:
105105
if (type(line) == bool) and line:
106106
logger.info(f"Sideloading {target} failed.")
107107
yield False
108-
else:
108+
else:
109109
yield True
110110

111111

@@ -121,7 +121,7 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str, config_path: Path) ->
121121
if (type(line) == bool) and not line:
122122
logger.error("Formatting data failed.")
123123
yield False
124-
return
124+
return
125125
sleep(1)
126126
# wipe some partitions
127127
for partition in ["cache", "system"]:
@@ -131,15 +131,15 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str, config_path: Path) ->
131131
if (type(line) == bool) and not line:
132132
logger.error(f"Wiping {partition} failed.")
133133
yield False
134-
return
134+
return
135135
# activate sideload
136136
logger.info("Wiping is done, now activate sideload.")
137137
for line in run_command("adb", ["shell", "twrp", "sideload"], bin_path):
138138
yield line
139139
if (type(line) == bool) and not line:
140140
logger.error("Activating sideload failed.")
141141
yield False
142-
return
142+
return
143143
# now flash os image
144144
sleep(5)
145145
logger.info("Sideload and install os image.")
@@ -149,7 +149,7 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str, config_path: Path) ->
149149
logger.error(f"Sideloading {target} failed.")
150150
# TODO: this might sometimes think it failed, but actually it's fine. So skip for now.
151151
# yield False
152-
# return
152+
# return
153153
# wipe some cache partitions
154154
sleep(7)
155155
for partition in ["dalvik", "cache"]:
@@ -164,17 +164,17 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str, config_path: Path) ->
164164
sleep(1)
165165
if (type(line) == bool) and not line:
166166
yield False
167-
return
167+
return
168168
break
169169
# finally reboot into os
170170
sleep(5)
171171
logger.info("Reboot into OS.")
172-
for line in run_command("adb", ["reboot"], bin_path): # "shell", "twrp",
172+
for line in run_command("adb", ["reboot"], bin_path): # "shell", "twrp",
173173
yield line
174174
if (type(line) == bool) and not line:
175175
logger.error("Rebooting failed.")
176176
yield False
177-
return
177+
return
178178
else:
179179
yield True
180180

@@ -187,67 +187,69 @@ def fastboot_unlock_with_code(bin_path: Path, unlock_code: str) -> bool:
187187
if (type(line) == bool) and not line:
188188
logger.error(f"Unlocking with code {unlock_code} failed.")
189189
yield False
190-
else:
190+
else:
191191
yield True
192192

193193

194194
def fastboot_unlock(bin_path: Path) -> bool:
195195
"""Unlock the device with fastboot and without code."""
196-
logger.info(f"Unlock the device with fastboot.")
196+
logger.info("Unlock the device with fastboot.")
197197
for line in run_command("adb", ["flashing", "unlock"], bin_path):
198198
yield line
199199
if (type(line) == bool) and not line:
200-
logger.error(f"Unlocking failed.")
200+
logger.error("Unlocking failed.")
201201
yield False
202-
else:
202+
else:
203203
yield True
204204

205205

206206
def fastboot_oem_unlock(bin_path: Path) -> bool:
207207
"""OEM unlock the device with fastboot and without code."""
208-
logger.info(f"OEM unlocking the device with fastboot.")
208+
logger.info("OEM unlocking the device with fastboot.")
209209
for line in run_command("adb", ["oem", "unlock"], bin_path):
210210
yield line
211211
if (type(line) == bool) and not line:
212-
logger.error(f"OEM unlocking failed.")
212+
logger.error("OEM unlocking failed.")
213213
yield False
214-
else:
214+
else:
215215
yield True
216216

217217

218218
def fastboot_reboot(bin_path: Path) -> bool:
219219
"""Reboot with fastboot"""
220-
logger.info(f"Rebooting device with fastboot.")
220+
logger.info("Rebooting device with fastboot.")
221221
for line in run_command("fastboot", ["reboot"], bin_path):
222222
yield line
223223
if (type(line) == bool) and not line:
224-
logger.error(f"Rebooting with fastboot failed.")
224+
logger.error("Rebooting with fastboot failed.")
225225
yield False
226-
else:
226+
else:
227227
yield True
228228

229229

230230
def fastboot_flash_recovery(bin_path: Path, recovery: str) -> bool:
231231
"""Temporarily, flash custom recovery with fastboot."""
232-
logger.info(f"Flash custom recovery with fastboot.")
232+
logger.info("Flash custom recovery with fastboot.")
233233
for line in run_command("fastboot", ["boot", f"{recovery}"], bin_path):
234234
yield line
235235
if (type(line) == bool) and not line:
236-
logger.error(f"Flashing recovery failed.")
236+
logger.error("Flashing recovery failed.")
237237
yield False
238-
else:
238+
else:
239239
yield True
240240

241241

242242
def heimdall_flash_recovery(bin_path: Path, recovery: str) -> bool:
243243
"""Temporarily, flash custom recovery with heimdall."""
244-
logger.info(f"Flash custom recovery with heimdall.")
245-
for line in run_command("heimdall", ["flash", "--no-reboot", "--RECOVERY", f"{recovery}"], bin_path):
244+
logger.info("Flash custom recovery with heimdall.")
245+
for line in run_command(
246+
"heimdall", ["flash", "--no-reboot", "--RECOVERY", f"{recovery}"], bin_path
247+
):
246248
yield line
247249
if (type(line) == bool) and not line:
248-
logger.error(f"Flashing recovery with heimdall failed.")
250+
logger.error("Flashing recovery with heimdall failed.")
249251
yield False
250-
else:
252+
else:
251253
yield True
252254

253255

@@ -287,5 +289,5 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
287289
logger.info(device_code)
288290
return device_code
289291
except CalledProcessError:
290-
logger.error(f"Failed to detect a device.")
292+
logger.error("Failed to detect a device.")
291293
return None

openandroidinstaller/utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from typing import Optional
1818

1919
import requests
20-
from installer_config import Step
2120
from loguru import logger
2221

2322

@@ -56,12 +55,16 @@ def image_recovery_works_with_device(
5655
logger.info(f"Image works with device: {supported_devices}")
5756

5857
recovery_file_name = recovery_path.split("/")[-1]
59-
if (device_code in supported_devices) and (
60-
device_code in recovery_file_name
61-
) and ("twrp" in recovery_file_name):
58+
if (
59+
(device_code in supported_devices)
60+
and (device_code in recovery_file_name)
61+
and ("twrp" in recovery_file_name)
62+
):
6263
logger.success("Device supported by the image and recovery.")
6364
return True
6465
else:
65-
logger.error(f"Recovery {recovery_file_name} and/or image {image_path.split('/')[-1]} are not supported or don't match.")
66+
logger.error(
67+
f"Recovery {recovery_file_name} and/or image {image_path.split('/')[-1]} are not supported or don't match."
68+
)
6669

6770
return False

0 commit comments

Comments
 (0)