Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor text fixes #174

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 13 additions & 37 deletions scripts/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ def firmware_menu(self, type: FlashMethod):
search_pattern = "*" # Default pattern for other types

Utils.header()
Utils.page(f"{type} Firmware Menu")
Utils.page(f"{type.value} Firmware Menu")

# Initialize and retrieve firmware only when this method is called
self.retrieve: RetrieveFirmware = RetrieveFirmware(
Expand Down Expand Up @@ -909,7 +909,7 @@ def confirm(self, type: FlashMethod):
raise ValueError("type cannot be None or empty")

Utils.header()
Utils.page(f"Confirm {type} Flash")
Utils.page(f"Confirm {type.value} Flash")

self.validator.check_selected_firmware()
self.validator.check_selected_device()
Expand All @@ -923,39 +923,16 @@ def confirm(self, type: FlashMethod):
Utils.colored_text("Firmware to Flash:", Color.MAGENTA),
self.selected_firmware,
)
if type not in {FlashMethod.CAN, FlashMethod.USB, FlashMethod.DFU}:
Utils.error_msg("Invalid Flash Method")

# Dynamically get the appropriate menu method based on `type`

# Map type to the appropriate object

# Type mapping to dynamically resolve the target object

type_mapping: Dict[str, Union[object, None]] = {
FlashMethod.CAN: self.can,
FlashMethod.USB: self.usb,
FlashMethod.DFU: self.dfu,
}

# Get the target object based on the `type`
target_object: Optional[object] = type_mapping.get(type.lower(), self)

# Ensure target_object exists
if not target_object:
Utils.error_msg(
f"Invalid type '{type}' provided; no corresponding object found."
)
return
# Dynamically get the appropriate menu method from the target object
menu_method_name: str = "menu" # Construct the menu method name
menu_method: Optional[Callable[[], None]] = getattr(
target_object, menu_method_name, None
)
if type == FlashMethod.CAN:
menu_method = self.can.menu
elif type == FlashMethod.USB:
menu_method = self.usb.menu
elif type == FlashMethod.DFU:
menu_method = self.dfu.menu

# Validate and call the menu method
if menu_method is None or not callable(menu_method):
Utils.error_msg(f"Menu for type '{type}' not found.")
return
# Ask for user confirmation
print("\nAre these details correct?")
menu_items: Dict[int, Union[Menu.Item, Menu.Separator]] = {
1: Menu.Item("Yes, proceed to flash", lambda: self.firmware_flash(type)),
Expand Down Expand Up @@ -1212,7 +1189,6 @@ def query_devices(self):
print("=" * 40)
else:
Utils.error_msg("No CAN devices found.")
self.menu()
else:
Utils.error_msg("Unexpected output format.")
self.menu()
Expand Down Expand Up @@ -1456,11 +1432,11 @@ def query_devices(self):
self.menu()

# Display the detected devices
print("Available Cartographe/Katapult Devices:")
print("=" * 40)
print("Available Cartographer/Katapult Devices:")
print("=" * PAGE_WIDTH)
for device in detected_devices:
print(device)
print("=" * 40)
print("=" * PAGE_WIDTH)

except Exception as e:
Utils.error_msg(f"Unexpected error while querying devices: {e}")
Expand Down
Loading