1616import sys
1717from pathlib import Path
1818from time import sleep
19- from subprocess import STDOUT , CalledProcessError , call , check_output , PIPE , run , CompletedProcess
19+ from subprocess import (
20+ STDOUT ,
21+ CalledProcessError ,
22+ call ,
23+ check_output ,
24+ PIPE ,
25+ run ,
26+ CompletedProcess ,
27+ )
2028from typing import Optional , List
2129
2230import regex as re
@@ -38,7 +46,7 @@ def run_command(tool: str, command: List[str], bin_path: Path) -> CompletedProce
3846 logger .info (f"Run command: { full_command } " )
3947 result = run (full_command , stdout = PIPE , stderr = PIPE , universal_newlines = True )
4048 # result contains result.returncode, result.stdout, result.stderr
41- return result
49+ return result
4250
4351
4452def adb_reboot (bin_path : Path ) -> bool :
@@ -92,7 +100,7 @@ def adb_sideload(bin_path: Path, target: str) -> bool:
92100
93101def adb_twrp_wipe_and_install (bin_path : Path , target : str ) -> bool :
94102 """Wipe and format data with twrp, then flash os image with adb.
95-
103+
96104 Only works for twrp recovery.
97105 """
98106 logger .info ("Wipe and format data with twrp, then install os image." )
@@ -137,7 +145,7 @@ def adb_twrp_wipe_and_install(bin_path: Path, target: str) -> bool:
137145 logger .info ("Rebooting with twrp failed." )
138146 return False
139147
140- return True
148+ return True
141149
142150
143151def fastboot_unlock_with_code (bin_path : Path , unlock_code : str ) -> bool :
@@ -148,22 +156,22 @@ def fastboot_unlock_with_code(bin_path: Path, unlock_code: str) -> bool:
148156 logger .info (f"Unlocking with code { unlock_code } failed." )
149157 return False
150158 return True
151-
159+
152160
153161def fastboot_unlock (bin_path : Path ) -> bool :
154162 """Unlock the device with fastboot and without code."""
155163 logger .info (f"Unlock the device with fastboot." )
156- result = run_command ("fastboot" , ["flashing" , "unlock" ] , bin_path )
164+ result = run_command ("fastboot" , ["flashing" , "unlock" ], bin_path )
157165 if result .returncode != 0 :
158166 logger .info (f"Unlocking failed." )
159167 return False
160168 return True
161-
169+
162170
163171def fastboot_oem_unlock (bin_path : Path ) -> bool :
164172 """OEM unlock the device with fastboot and without code."""
165173 logger .info (f"OEM unlocking the device with fastboot." )
166- result = run_command ("fastboot" , ["oem" , "unlock" ] , bin_path )
174+ result = run_command ("fastboot" , ["oem" , "unlock" ], bin_path )
167175 if result .returncode != 0 :
168176 logger .info (f"OEM unlocking failed." )
169177 return False
@@ -173,27 +181,29 @@ def fastboot_oem_unlock(bin_path: Path) -> bool:
173181def fastboot_reboot (bin_path : Path ) -> bool :
174182 """Reboot with fastboot"""
175183 logger .info (f"Rebooting device with fastboot." )
176- result = run_command ("fastboot" , ["reboot" ] , bin_path )
184+ result = run_command ("fastboot" , ["reboot" ], bin_path )
177185 if result .returncode != 0 :
178186 logger .info (f"Rebooting with fastboot failed." )
179187 return False
180188 return True
181-
189+
182190
183191def fastboot_flash_recovery (bin_path : Path , recovery : str ) -> bool :
184192 """Temporarily, flash custom recovery with fastboot."""
185193 logger .info (f"Flash custom recovery with fastboot." )
186- result = run_command ("fastboot" , ["boot" , f"{ recovery } " ] , bin_path )
194+ result = run_command ("fastboot" , ["boot" , f"{ recovery } " ], bin_path )
187195 if result .returncode != 0 :
188196 logger .info (f"Flashing recovery failed." )
189197 return False
190198 return True
191-
199+
192200
193201def heimdall_flash_recovery (bin_path : Path , recovery : str ) -> bool :
194202 """Temporarily, flash custom recovery with heimdall."""
195203 logger .info (f"Flash custom recovery with heimdall." )
196- result = run_command ("heimdall" , ["flash" , "--no-reboot" , "--RECOVERY" , f"{ recovery } " ] , bin_path )
204+ result = run_command (
205+ "heimdall" , ["flash" , "--no-reboot" , "--RECOVERY" , f"{ recovery } " ], bin_path
206+ )
197207 if result .returncode != 0 :
198208 logger .info (f"Flashing recovery failed." )
199209 return False
0 commit comments