Skip to content

Commit

Permalink
changed airgap_update_screen to allow listing of multiple usb devices
Browse files Browse the repository at this point in the history
  • Loading branch information
qlrd committed Oct 25, 2024
1 parent 3084c34 commit 1ad1589
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 234 deletions.
76 changes: 34 additions & 42 deletions src/app/screens/airgap_update_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
main_screen.py
"""
import os
import sys
import shutil
from functools import partial
from kivy.clock import Clock
Expand All @@ -37,36 +36,36 @@ def __init__(self, **kwargs):
super().__init__(
wid="airgap_update_screen", name="AirgapUpdateScreen", **kwargs
)
self.make_grid(wid=f"{self.id}_grid", rows=1)

self._firmware_bin = ""
self._firmware_sig = ""

# pylint: disable=unused-argument
def on_enter(self, *args, **kwargs):
"""When enter, verify if system is windows or other and give
a proper way to show folders"""
self.ids[f"{self.id}_grid"].clear_widgets()

def on_load(path):
new_firmware_bin = os.path.join(path, "firmware.bin")
self.info(f"Copying file {self.firmware_bin} to {new_firmware_bin}")
shutil.copyfile(self.firmware_bin, new_firmware_bin)
def build_drive_button(self, row: int, drive: str):
"""dynamically create a callback for copy process"""

new_firmware_sig = os.path.join(path, "firmware.bin.sig")
self.info(f"Copying file {self.firmware_sig} to {new_firmware_sig}")
def on_press(instance):
self.debug(f"Calling {instance.id}::on_press")
self.set_background(wid=instance.id, rgba=(0.25, 0.25, 0.25, 1))

Check warning on line 48 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L46-L48

Added lines #L46 - L48 were not covered by tests

def on_release(instance):
new_firmware_bin = os.path.join(drive, "firmware.bin")
new_firmware_sig = os.path.join(drive, "firmware.bin.sig")
shutil.copyfile(self.firmware_bin, new_firmware_bin)
shutil.copyfile(self.firmware_sig, new_firmware_sig)

Check warning on line 54 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L50-L54

Added lines #L50 - L54 were not covered by tests

# After copy, make sha256 hash to show
sha256 = Sha256Verifyer(filename=new_firmware_bin)
sha256.load()

Check warning on line 58 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L57-L58

Added lines #L57 - L58 were not covered by tests

# Now update the next screen
warn_screen = self.manager.get_screen("WarningAfterAirgapUpdateScreen")

Check warning on line 61 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L61

Added line #L61 was not covered by tests

fns = [

Check warning on line 63 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L63

Added line #L63 was not covered by tests
partial(
warn_screen.update,
name=self.name,
key="sdcard",
value=path,
value=drive,
),
partial(
warn_screen.update,
Expand All @@ -80,37 +79,25 @@ def on_load(path):
for fn in fns:
Clock.schedule_once(fn, 0)

Check warning on line 80 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L80

Added line #L80 was not covered by tests

self.set_background(wid=instance.id, rgba=(0, 0, 0, 1))
self.set_screen(name="WarningAfterAirgapUpdateScreen", direction="left")

Check warning on line 83 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L82-L83

Added lines #L82 - L83 were not covered by tests

setattr(AirgapUpdateScreen, "on_load", on_load)

def on_filter_sys(directory, filename):
if sys.platform == "win32":
return not directory == "C:\\" and not filename.endswith(".sys")
return True

def on_filter_dumpstack(directory, filename):
if sys.platform == "win32":
return not directory == "C:\\" and not filename.endswith(
"DumpStack.log.tmp"
)
return True

setattr(
AirgapUpdateScreen, "on_filters_list", [on_filter_sys, on_filter_dumpstack]
)

self.make_file_chooser(
wid=f"{self.id}_select",
# Now build the button
self.make_button(

Check warning on line 86 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L86

Added line #L86 was not covered by tests
root_widget=f"{self.id}_grid",
view_mode="icon",
font_factor=44,
on_load=getattr(AirgapUpdateScreen, "on_load"),
on_filters_list=getattr(AirgapUpdateScreen, "on_filters_list"),
wid=f"{self.id}_button_{row}",
text=f"Select {drive} to copy firmware",
row=row,
halign="center",
font_factor=36,
on_press=on_press,
on_release=on_release,
on_ref_press=None,
)

fn = partial(self.update, name=self.name, key="canvas")
Clock.schedule_once(fn, 0)
# pylint: disable=unused-argument
def on_leave(self, *args):
self.clear_widgets()

Check warning on line 100 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L100

Added line #L100 was not covered by tests

@property
def firmware_bin(self) -> str:
Expand Down Expand Up @@ -144,6 +131,11 @@ def update(self, *args, **kwargs):
value = kwargs.get("value")

Check warning on line 131 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L129-L131

Added lines #L129 - L131 were not covered by tests

def on_update():

Check warning on line 133 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L133

Added line #L133 was not covered by tests
if key == "drives":
self.make_grid(wid=f"{self.id}_grid", rows=len(value))

Check warning on line 135 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L135

Added line #L135 was not covered by tests
for i, drive in enumerate(value):
self.build_drive_button(row=i, drive=drive)

Check warning on line 137 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L137

Added line #L137 was not covered by tests

if key == "binary":
self.firmware_bin = value

Check warning on line 140 in src/app/screens/airgap_update_screen.py

View check run for this annotation

Codecov / codecov/patch

src/app/screens/airgap_update_screen.py#L140

Added line #L140 was not covered by tests

Expand All @@ -158,7 +150,7 @@ def on_update():
allowed_screens=(
"ConfigKruxInstaller",
"UnzipStableScreen",
"DownloadBetaScreen",
"WarningBeforeAirgapUpdateScreen",
"AirgapUpdateScreen",
),
on_update=getattr(AirgapUpdateScreen, "on_update"),
Expand Down
Loading

0 comments on commit 1ad1589

Please sign in to comment.