Skip to content

Commit

Permalink
Minor cleanup of flasher script. (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisen authored Jul 4, 2024
2 parents 9158ade + abb5385 commit d229e3e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions zehardware/zefirmware/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.32.3
17 changes: 11 additions & 6 deletions zehardware/zefirmware/zeflash.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import subprocess
import time
from typing import Optional

import requests

Expand All @@ -14,6 +15,7 @@
BASE_URL = "https://zebadge.app/"

BASE_BADGE_PATH = "/Volumes"
FIRMWARE_DIR = "firmware"


def hsv(h, s, v):
Expand Down Expand Up @@ -138,14 +140,12 @@ def find_base_badge_path():


def nuke():
nuke_ware = list(filter(lambda x: 'nuke' in x, os.listdir("./")))
nuke_ware = find_firmware_file("nuke")

if not nuke_ware:
print(colorize("No nuke firmware found!"))
return False

nuke_ware = nuke_ware[0]

path = find_mount_point('RPI')
if not path:
print(
Expand Down Expand Up @@ -173,14 +173,12 @@ def nuke():


def flash():
zepython = list(filter(lambda x: 'zepython' in x, os.listdir("./")))
zepython = find_firmware_file("zepython")

if not zepython:
print(colorize("No zepython firmware found!"))
return False

zepython = zepython[0]

path = find_mount_point('RPI')
if not path:
print(f"Please put badge in flash mode.\n{colorize('restart')} and hold {colorize('boot / usr')} button.")
Expand Down Expand Up @@ -283,6 +281,13 @@ def inject_user(user):
).content
)

def find_firmware_file(name: str) -> Optional[str]:
matching_files = list(filter(lambda x: name in x, os.listdir(f"./{FIRMWARE_DIR}/")))
if matching_files:
return os.path.join(FIRMWARE_DIR, matching_files[0])
else:
return None


def doit():
badge_path = find_base_badge_path()
Expand Down

0 comments on commit d229e3e

Please sign in to comment.