Skip to content

Commit 74b974c

Browse files
committed
Format and lint
1 parent 3b5dd53 commit 74b974c

8 files changed

Lines changed: 84 additions & 40 deletions

File tree

openandroidinstaller/openandroidinstaller.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@
3838
from loguru import logger
3939

4040
from app_state import AppState
41-
from views import SelectFilesView, StepView, SuccessView, StartView, RequirementsView, WelcomeView
41+
from views import (
42+
SelectFilesView,
43+
StepView,
44+
SuccessView,
45+
StartView,
46+
RequirementsView,
47+
WelcomeView,
48+
)
4249
from tooling import run_command
4350

4451
# where to write the logs
@@ -92,7 +99,12 @@ def __init__(self):
9299
state=self.state,
93100
)
94101
# ordered to allow for pop
95-
self.default_views = [select_files_view, requirements_view, start_view, welcome_view]
102+
self.default_views = [
103+
select_files_view,
104+
requirements_view,
105+
start_view,
106+
welcome_view,
107+
]
96108
# create the final success view
97109
self.final_view = SuccessView(state=self.state)
98110

openandroidinstaller/utils.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def get_download_link(devicecode: str) -> Optional[str]:
3939
return
4040

4141

42-
def image_works_with_device(
43-
device_code: str, image_path: str
44-
) -> bool:
42+
def image_works_with_device(device_code: str, image_path: str) -> bool:
4543
"""Determine if an image works for the given device."""
4644
with zipfile.ZipFile(image_path) as image_zip:
4745
with image_zip.open(
@@ -51,17 +49,17 @@ def image_works_with_device(
5149
supported_devices = str(metadata[-1]).split("=")[-1][:-3].split(",")
5250
logger.info(f"Image works with device: {supported_devices}")
5351

54-
if (device_code in supported_devices):
52+
if device_code in supported_devices:
5553
logger.success("Device supported by the selected image.")
5654
return True
5755
else:
58-
logger.error(f"Image file {image_path.split('/')[-1]} is not supported.")
56+
logger.error(
57+
f"Image file {image_path.split('/')[-1]} is not supported."
58+
)
5959
return False
6060

6161

62-
def recovery_works_with_device(
63-
device_code: str, recovery_path: str
64-
) -> bool:
62+
def recovery_works_with_device(device_code: str, recovery_path: str) -> bool:
6563
"""Determine if a recovery works for the given device.
6664
6765
BEWARE: THE RECOVERY PART IS STILL VERY BASIC!
@@ -72,4 +70,4 @@ def recovery_works_with_device(
7270
return True
7371
else:
7472
logger.error(f"Recovery file {recovery_file_name} is not supported.")
75-
return False
73+
return False

openandroidinstaller/views/requirements_view.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
)
3030

3131
from views import BaseView
32-
from components import ConfirmButton
3332
from app_state import AppState
3433
from widgets import get_title
3534

@@ -57,7 +56,10 @@ def build(self):
5756
# build up the main view
5857
self.right_view.controls.extend(
5958
[
60-
get_title("Check the Requirements", step_indicator_img="steps-header-requirements.png"),
59+
get_title(
60+
"Check the Requirements",
61+
step_indicator_img="steps-header-requirements.png",
62+
),
6163
Text(
6264
"Before continuing you need to check some requirements to progress. Please read the instructions and check the boxes if everything is fine."
6365
),

openandroidinstaller/views/select_view.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@
3838
from views import BaseView
3939
from app_state import AppState
4040
from widgets import get_title, confirm_button
41-
from utils import (
42-
get_download_link,
43-
image_works_with_device,
44-
recovery_works_with_device
45-
)
41+
from utils import get_download_link, image_works_with_device, recovery_works_with_device
4642

4743

4844
class SelectFilesView(BaseView):
@@ -60,7 +56,7 @@ def build(self):
6056
modal=True,
6157
title=Text("What is an OS image and recovery and why do I need it?"),
6258
content=Markdown(
63-
"""## OS image or ROM
59+
"""## OS image or ROM
6460
An operating system (OS) is system software that manages computer hardware,
6561
software resources, and provides common services for computer programs.
6662
Popular, custom operating systems for mobile devices based on Android are
@@ -117,16 +113,20 @@ def build(self):
117113
icon_color=colors.DEEP_ORANGE_500,
118114
tooltip="Get more details on custom operating system images and recoveries.",
119115
)
120-
#info_button = IconButton(
116+
# info_button = IconButton(
121117
# icon=icons.HELP_OUTLINE_OUTLINED,
122118
# icon_color=colors.DEEP_ORANGE_500,
123119
# icon_size=30,
124120
# on_click=self.open_explain_images_dlg,
125121
# tooltip="What is an OS image and a recovery file?",
126-
#)
122+
# )
127123
# add title and progressbar
128124
self.right_view.controls.append(
129-
get_title("Now pick an OS image and a recovery file:", info_button=info_button, step_indicator_img="steps-header-select.png")
125+
get_title(
126+
"Now pick an OS image and a recovery file:",
127+
info_button=info_button,
128+
step_indicator_img="steps-header-select.png",
129+
)
130130
)
131131
self.right_view.controls.append(self.state.progressbar)
132132

@@ -195,7 +195,7 @@ def build(self):
195195
The recovery image should look something like `twrp-3.6.2_9-0-{self.state.config.metadata.get('devicecode')}.img`.
196196
197197
**Note:** This tool **only supports TWRP recoveries**.""",
198-
extension_set="gitHubFlavored"
198+
extension_set="gitHubFlavored",
199199
),
200200
Row(
201201
[
@@ -245,7 +245,9 @@ def pick_image_result(self, e: FilePickerResultEvent):
245245
# check if the image works with the device and show the filename in different colors accordingly
246246
if e.files:
247247
device_code = self.state.config.metadata.get("devicecode")
248-
if image_works_with_device(device_code=device_code, image_path=self.state.image_path):
248+
if image_works_with_device(
249+
device_code=device_code, image_path=self.state.image_path
250+
):
249251
self.selected_image.color = colors.GREEN
250252
else:
251253
self.selected_image.color = colors.RED
@@ -267,7 +269,9 @@ def pick_recovery_result(self, e: FilePickerResultEvent):
267269
# check if the recovery works with the device and show the filename in different colors accordingly
268270
if e.files:
269271
device_code = self.state.config.metadata.get("devicecode")
270-
if recovery_works_with_device(device_code=device_code, recovery_path=self.state.recovery_path):
272+
if recovery_works_with_device(
273+
device_code=device_code, recovery_path=self.state.recovery_path
274+
):
271275
self.selected_recovery.color = colors.GREEN
272276
else:
273277
self.selected_recovery.color = colors.RED
@@ -280,8 +284,13 @@ def enable_button_if_ready(self, e):
280284
".img" in self.selected_recovery.value
281285
):
282286
device_code = self.state.config.metadata.get("devicecode")
283-
if not (image_works_with_device(device_code=device_code, image_path=self.state.image_path)
284-
and recovery_works_with_device(device_code=device_code, recovery_path=self.state.recovery_path)
287+
if not (
288+
image_works_with_device(
289+
device_code=device_code, image_path=self.state.image_path
290+
)
291+
and recovery_works_with_device(
292+
device_code=device_code, recovery_path=self.state.recovery_path
293+
)
285294
):
286295
# if image and recovery work for device allow to move on, otherwise display message
287296
logger.error(
@@ -290,7 +299,8 @@ def enable_button_if_ready(self, e):
290299
self.info_field.controls = [
291300
Text(
292301
"Image and/or recovery don't work with the device. Make sure you use a TWRP-based recovery.",
293-
color=colors.RED, weight="bold",
302+
color=colors.RED,
303+
weight="bold",
294304
)
295305
]
296306
self.confirm_button.disabled = True

openandroidinstaller/views/start_view.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
Column,
2323
Divider,
2424
ElevatedButton,
25-
Image,
2625
OutlinedButton,
2726
FilledButton,
2827
Markdown,
@@ -35,7 +34,6 @@
3534
from flet.buttons import CountinuosRectangleBorder
3635

3736
from views import BaseView
38-
from components import ConfirmButton
3937
from app_state import AppState
4038
from widgets import get_title
4139
from tooling import search_device
@@ -114,7 +112,10 @@ def check_bootloader_unlocked(e):
114112
# build up the main view
115113
self.right_view.controls.extend(
116114
[
117-
get_title("Get the phone ready", step_indicator_img="steps-header-get-ready.png"),
115+
get_title(
116+
"Get the phone ready",
117+
step_indicator_img="steps-header-get-ready.png",
118+
),
118119
Markdown(
119120
"""
120121
To get started you need to

openandroidinstaller/views/step_view.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ def check_advanced_switch(e):
107107
"Install OS": "steps-header-install.png",
108108
}
109109
self.right_view.controls = [
110-
get_title(f"{self.step.title}", step_indicator_img=steps_indictor_img_lookup.get(self.step.title)),
110+
get_title(
111+
f"{self.step.title}",
112+
step_indicator_img=steps_indictor_img_lookup.get(self.step.title),
113+
),
111114
self.state.progressbar,
112115
Text(f"{self.step.content}"),
113116
]

openandroidinstaller/views/welcome_view.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# If not, see <https://www.gnu.org/licenses/>."""
1414
# Author: Tobias Sterbak
1515

16-
from loguru import logger
1716
from typing import Callable
1817

1918
from flet import (
@@ -75,4 +74,4 @@ def build(self):
7574
),
7675
]
7776
)
78-
return self.view
77+
return self.view

openandroidinstaller/widgets.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,38 @@
1717
from functools import partial
1818
from typing import Callable
1919

20-
from flet import Container, ElevatedButton, Row, Text, alignment, icons, IconButton, Image, Column
20+
from flet import (
21+
Container,
22+
ElevatedButton,
23+
Row,
24+
Text,
25+
alignment,
26+
icons,
27+
IconButton,
28+
Image,
29+
Column,
30+
)
2131

2232

23-
def get_title(title: str, info_button: IconButton=None, step_indicator_img: str=None) -> Container:
33+
def get_title(
34+
title: str, info_button: IconButton = None, step_indicator_img: str = None
35+
) -> Container:
2436
if info_button:
2537
content = Row([Text(f"{title}", style="titleLarge"), info_button])
2638
else:
2739
content = Row([Text(f"{title}", style="titleLarge")])
2840
if step_indicator_img:
29-
content = Column(controls=[
30-
Image(src=f"/assets/imgs/{step_indicator_img}", fit="fitWidth", tooltip=f"Current step: {title}", width=600),
31-
content
32-
])
41+
content = Column(
42+
controls=[
43+
Image(
44+
src=f"/assets/imgs/{step_indicator_img}",
45+
fit="fitWidth",
46+
tooltip=f"Current step: {title}",
47+
width=600,
48+
),
49+
content,
50+
]
51+
)
3352
return Container(
3453
content=content,
3554
margin=0,

0 commit comments

Comments
 (0)