Skip to content

Commit a95b93b

Browse files
committed
Improve logging
1 parent ab737e8 commit a95b93b

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

openandroidinstaller/installer_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def validate_config(config: str) -> bool:
148148
)
149149
try:
150150
config_schema.validate(config)
151-
logger.info("Config is valid.")
151+
logger.success("Config is valid.")
152152
return True
153153
except SchemaError as se:
154-
logger.info(f"Config is invalid. Error {se}")
154+
logger.error(f"Config is invalid. Error {se}")
155155
return False

openandroidinstaller/openandroidinstaller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def confirm(self, e):
119119
else:
120120
# display the final view
121121
self.view.controls.append(self.final_view)
122+
logger.info("Confirmed.")
122123
self.view.update()
123124

124125

openandroidinstaller/tool_utils.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def adb_reboot(bin_path: Path) -> bool:
5757
for line in run_command("adb", ["reboot"], bin_path):
5858
yield line
5959
if (type(line) == bool) and line:
60-
logger.info("Reboot failed.")
60+
logger.debug("Reboot failed.")
6161
yield False
6262
else:
6363
yield True
@@ -69,15 +69,15 @@ def adb_reboot_bootloader(bin_path: Path) -> bool:
6969
for line in run_command("adb", ["reboot", "bootloader"], bin_path):
7070
yield line
7171
if (type(line) == bool) and not line:
72-
logger.info("Reboot into bootloader failed.")
72+
logger.error("Reboot into bootloader failed.")
7373
yield False
7474
return
7575
sleep(1)
7676
# check if in fastboot mode
7777
for line in run_command("fastboot", ["devices"], bin_path):
7878
yield line
7979
if (type(line) == bool) and not line:
80-
logger.info("No fastboot mode detected. Reboot into bootloader failed.")
80+
logger.error("No fastboot mode detected. Reboot into bootloader failed.")
8181
yield False
8282
else:
8383
yield True
@@ -89,7 +89,7 @@ def adb_reboot_download(bin_path: Path) -> bool:
8989
for line in run_command("adb", ["reboot", "download"], bin_path):
9090
yield line
9191
if (type(line) == bool) and not line:
92-
logger.info("Reboot into download mode failed.")
92+
logger.error("Reboot into download mode failed.")
9393
yield False
9494
else:
9595
# check if in download mode with heimdall?
@@ -118,7 +118,7 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str) -> bool:
118118
for line in run_command("adb", ["shell", "twrp", "format", "data"], bin_path):
119119
yield line
120120
if (type(line) == bool) and not line:
121-
logger.info("Formatting data failed.")
121+
logger.error("Formatting data failed.")
122122
yield False
123123
return
124124
sleep(1)
@@ -128,15 +128,15 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str) -> bool:
128128
yield not line
129129
sleep(1)
130130
if (type(line) == bool) and not line:
131-
logger.info(f"Wiping {partition} failed.")
131+
logger.error(f"Wiping {partition} failed.")
132132
yield False
133133
return
134134
# activate sideload
135135
logger.info("Wiping is done, now activate sideload.")
136136
for line in run_command("adb", ["shell", "twrp", "sideload"], bin_path):
137137
yield line
138138
if (type(line) == bool) and not line:
139-
logger.info("Activating sideload failed.")
139+
logger.error("Activating sideload failed.")
140140
yield False
141141
return
142142
# now flash os image
@@ -145,7 +145,7 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str) -> bool:
145145
for line in run_command("adb", ["sideload", f"{target}"], bin_path):
146146
yield line
147147
if (type(line) == bool) and not line:
148-
logger.info(f"Sideloading {target} failed.")
148+
logger.error(f"Sideloading {target} failed.")
149149
yield False
150150
return
151151
# wipe some cache partitions
@@ -155,7 +155,7 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str) -> bool:
155155
yield line
156156
sleep(1)
157157
if (type(line) == bool) and not line:
158-
logger.info(f"Wiping {partition} failed.")
158+
logger.error(f"Wiping {partition} failed.")
159159
yield False
160160
return
161161
# finally reboot into os
@@ -164,7 +164,7 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str) -> bool:
164164
for line in run_command("adb", ["shell", "twrp", "reboot"], bin_path):
165165
yield line
166166
if (type(line) == bool) and not line:
167-
logger.info("Rebooting with twrp failed.")
167+
logger.error("Rebooting with twrp failed.")
168168
yield False
169169
return
170170
else:
@@ -177,7 +177,7 @@ def fastboot_unlock_with_code(bin_path: Path, unlock_code: str) -> bool:
177177
for line in run_command("adb", ["oem", "unlock", f"{unlock_code}"], bin_path):
178178
yield line
179179
if (type(line) == bool) and not line:
180-
logger.info(f"Unlocking with code {unlock_code} failed.")
180+
logger.error(f"Unlocking with code {unlock_code} failed.")
181181
yield False
182182
else:
183183
yield True
@@ -189,7 +189,7 @@ def fastboot_unlock(bin_path: Path) -> bool:
189189
for line in run_command("adb", ["flashing", "unlock"], bin_path):
190190
yield line
191191
if (type(line) == bool) and not line:
192-
logger.info(f"Unlocking failed.")
192+
logger.error(f"Unlocking failed.")
193193
yield False
194194
else:
195195
yield True
@@ -201,7 +201,7 @@ def fastboot_oem_unlock(bin_path: Path) -> bool:
201201
for line in run_command("adb", ["oem", "unlock"], bin_path):
202202
yield line
203203
if (type(line) == bool) and not line:
204-
logger.info(f"OEM unlocking failed.")
204+
logger.error(f"OEM unlocking failed.")
205205
yield False
206206
else:
207207
yield True
@@ -213,7 +213,7 @@ def fastboot_reboot(bin_path: Path) -> bool:
213213
for line in run_command("fastboot", ["reboot"], bin_path):
214214
yield line
215215
if (type(line) == bool) and not line:
216-
logger.info(f"Rebooting with fastboot failed.")
216+
logger.error(f"Rebooting with fastboot failed.")
217217
yield False
218218
else:
219219
yield True
@@ -225,7 +225,7 @@ def fastboot_flash_recovery(bin_path: Path, recovery: str) -> bool:
225225
for line in run_command("fastboot", ["boot", f"{recovery}"], bin_path):
226226
yield line
227227
if (type(line) == bool) and not line:
228-
logger.info(f"Flashing recovery failed.")
228+
logger.error(f"Flashing recovery failed.")
229229
yield False
230230
else:
231231
yield True
@@ -237,7 +237,7 @@ def heimdall_flash_recovery(bin_path: Path, recovery: str) -> bool:
237237
for line in run_command("heimdall", ["flash", "--no-reboot", "--RECOVERY", f"{recovery}"], bin_path):
238238
yield line
239239
if (type(line) == bool) and not line:
240-
logger.info(f"Flashing recovery with heimdall failed.")
240+
logger.error(f"Flashing recovery with heimdall failed.")
241241
yield False
242242
else:
243243
yield True
@@ -279,5 +279,5 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
279279
logger.info(device_code)
280280
return device_code
281281
except CalledProcessError:
282-
logger.info(f"Failed to detect a device.")
282+
logger.error(f"Failed to detect a device.")
283283
return None

openandroidinstaller/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_download_link(devicecode: str) -> Optional[str]:
3636
logger.info(f"{url} doesn't exist, status_code: {res.status_code}")
3737
return
3838
except requests.exceptions.RequestException as e:
39-
logger.info(f"{url} doesn't exist, error: {e}")
39+
logger.error(f"{url} doesn't exist, error: {e}")
4040
return
4141

4242

@@ -59,9 +59,9 @@ def image_recovery_works_with_device(
5959
if (device_code in supported_devices) and (
6060
device_code in recovery_file_name
6161
) and ("twrp" in recovery_file_name):
62-
logger.info("Device supported by the image and recovery.")
62+
logger.success("Device supported by the image and recovery.")
6363
return True
6464
else:
65-
logger.info(f"Recovery {recovery_file_name} and/or image {image_path.split('/')[-1]} are not supported or don't match.")
65+
logger.error(f"Recovery {recovery_file_name} and/or image {image_path.split('/')[-1]} are not supported or don't match.")
6666

6767
return False

openandroidinstaller/views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def search_devices(self, e):
247247
device_code = device_code_mapping.get(device_code, device_code)
248248
self.device_name.value = device_code
249249
else:
250+
logger.info("No device detected! Connect to USB and try again.")
250251
self.device_name.value = (
251252
"No device detected! Connect to USB and try again."
252253
)
@@ -269,7 +270,7 @@ def search_devices(self, e):
269270
self.device_name.value = f"{device_name} (code: {device_code})"
270271
else:
271272
# failed to load config
272-
logger.info(f"Failed to load config for {device_code}.")
273+
logger.error(f"Failed to load config for {device_code}.")
273274
self.device_name.value = f"Failed to load config for {device_code}."
274275
self.view.update()
275276

@@ -426,13 +427,15 @@ def enable_button_if_ready(self, e):
426427
recovery_path=self.state.recovery_path,
427428
):
428429
# if image and recovery work for device allow to move on, otherwise display message
430+
logger.error("Image and recovery don't work with the device. Please select different ones.")
429431
self.info_field.controls = [
430432
Text(
431433
"Image and recovery don't work with the device. Please select different ones."
432434
)
433435
]
434436
self.right_view.update()
435437
return
438+
logger.info("Image and recovery work with the device. You can continue.")
436439
self.info_field.controls = []
437440
self.confirm_button.disabled = False
438441
self.right_view.update()
@@ -476,6 +479,7 @@ def build(self):
476479
Text(f"{self.step.content}"),
477480
]
478481
# basic view depending on step.type
482+
logger.info(f"Starting step of type {self.step.type}.")
479483
self.confirm_button = confirm_button(self.on_confirm)
480484
if self.step.type == "confirm_button":
481485
self.right_view.controls.append(Row([self.confirm_button]))
@@ -506,6 +510,7 @@ def build(self):
506510
)
507511

508512
elif self.step.type != "text":
513+
logger.error(f"Unknown step type: {self.step.type}")
509514
raise Exception(f"Unknown step type: {self.step.type}")
510515

511516
# if skipping is allowed add a button to the view
@@ -590,6 +595,7 @@ def call_to_phone(self, e, command: str):
590595
self.terminal_box.update()
591596
success = line
592597
else:
598+
logger.error(f"Unknown command type: {command}. Stopping.")
593599
raise Exception(f"Unknown command type: {command}. Stopping.")
594600

595601
# update the view accordingly
@@ -603,6 +609,7 @@ def call_to_phone(self, e, command: str):
603609
)
604610
else:
605611
sleep(5) # wait to make sure everything is fine
612+
logger.success(f"Command {command} run successfully. Allow to continue.")
606613
# pop the progress bar
607614
self.right_view.controls.pop()
608615
self.confirm_button.disabled = False

0 commit comments

Comments
 (0)