mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-05-06 22:06:04 +02:00
Run UV Ruff over tools scripts
This commit is contained in:
@@ -314,6 +314,7 @@ def get_serial_info(device: OpenIrisDevice) -> dict:
|
|||||||
"mac": response["results"][0]["result"]["data"]["mac"],
|
"mac": response["results"][0]["result"]["data"]["mac"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_device_info(device: OpenIrisDevice) -> dict:
|
def get_device_info(device: OpenIrisDevice) -> dict:
|
||||||
response = device.send_command("get_who_am_i")
|
response = device.send_command("get_who_am_i")
|
||||||
|
|
||||||
@@ -321,7 +322,10 @@ def get_device_info(device: OpenIrisDevice) -> dict:
|
|||||||
print(f"❌ Failed to get device info: {response['error']}")
|
print(f"❌ Failed to get device info: {response['error']}")
|
||||||
return {"who_am_i": None, "version": None}
|
return {"who_am_i": None, "version": None}
|
||||||
|
|
||||||
return {"who_am_i": response["results"][0]["result"]["data"]["who_am_i"], "version": response["results"][0]["result"]["data"]["version"]}
|
return {
|
||||||
|
"who_am_i": response["results"][0]["result"]["data"]["who_am_i"],
|
||||||
|
"version": response["results"][0]["result"]["data"]["version"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_wifi_status(device: OpenIrisDevice) -> dict:
|
def get_wifi_status(device: OpenIrisDevice) -> dict:
|
||||||
@@ -339,7 +343,9 @@ def get_led_current(device: OpenIrisDevice) -> dict:
|
|||||||
print(f"❌ Failed to get LED current: {response}")
|
print(f"❌ Failed to get LED current: {response}")
|
||||||
return {"led_current_ma": "unknown"}
|
return {"led_current_ma": "unknown"}
|
||||||
|
|
||||||
return {"led_current_ma": response["results"][0]["result"]["data"]["led_current_ma"]}
|
return {
|
||||||
|
"led_current_ma": response["results"][0]["result"]["data"]["led_current_ma"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def configure_device_name(device: OpenIrisDevice, *args, **kwargs):
|
def configure_device_name(device: OpenIrisDevice, *args, **kwargs):
|
||||||
@@ -479,7 +485,6 @@ def get_settings_summary(device: OpenIrisDevice, *args, **kwargs):
|
|||||||
if ver:
|
if ver:
|
||||||
print(f"🧭 Version: {ver}")
|
print(f"🧭 Version: {ver}")
|
||||||
|
|
||||||
|
|
||||||
wifi = summary.get("WiFi", {}).get("wifi_status", {})
|
wifi = summary.get("WiFi", {}).get("wifi_status", {})
|
||||||
if wifi:
|
if wifi:
|
||||||
status = wifi.get("status", "unknown")
|
status = wifi.get("status", "unknown")
|
||||||
|
|||||||
+57
-22
@@ -4,14 +4,15 @@ import argparse
|
|||||||
from typing import Dict, Optional, List
|
from typing import Dict, Optional, List
|
||||||
|
|
||||||
HEADER_COLOR = "\033[95m"
|
HEADER_COLOR = "\033[95m"
|
||||||
OKGREEN = '\033[92m'
|
OKGREEN = "\033[92m"
|
||||||
WARNING = '\033[93m'
|
WARNING = "\033[93m"
|
||||||
OKBLUE = '\033[94m'
|
OKBLUE = "\033[94m"
|
||||||
ENDC = '\033[0m'
|
ENDC = "\033[0m"
|
||||||
|
|
||||||
BOARDS_DIR_NAME = "boards"
|
BOARDS_DIR_NAME = "boards"
|
||||||
SDKCONFIG_DEFAULTS_FILENAME = "sdkconfig.base_defaults"
|
SDKCONFIG_DEFAULTS_FILENAME = "sdkconfig.base_defaults"
|
||||||
|
|
||||||
|
|
||||||
def get_root_path() -> str:
|
def get_root_path() -> str:
|
||||||
return os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
|
return os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
|
||||||
|
|
||||||
@@ -47,23 +48,36 @@ def enumerate_board_configs() -> Dict[str, str]:
|
|||||||
|
|
||||||
BOARD_CONFIGS = enumerate_board_configs()
|
BOARD_CONFIGS = enumerate_board_configs()
|
||||||
|
|
||||||
|
|
||||||
def build_arg_parser() -> argparse.ArgumentParser:
|
def build_arg_parser() -> argparse.ArgumentParser:
|
||||||
p = argparse.ArgumentParser()
|
p = argparse.ArgumentParser()
|
||||||
p.add_argument("-b", "--board", help="Board name (run with --list to see options). Flexible: accepts path-like or partial if unique.")
|
p.add_argument(
|
||||||
p.add_argument("--list", help="List discovered boards and exit", action="store_true")
|
"-b",
|
||||||
|
"--board",
|
||||||
|
help="Board name (run with --list to see options). Flexible: accepts path-like or partial if unique.",
|
||||||
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"--list", help="List discovered boards and exit", action="store_true"
|
||||||
|
)
|
||||||
p.add_argument("--dry-run", help="Dry run, won't modify files", action="store_true")
|
p.add_argument("--dry-run", help="Dry run, won't modify files", action="store_true")
|
||||||
p.add_argument("--diff", help="Show the difference between base config and selected board", action="store_true")
|
p.add_argument(
|
||||||
|
"--diff",
|
||||||
|
help="Show the difference between base config and selected board",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
p.add_argument("--ssid", help="Set the WiFi SSID", type=str, default="")
|
p.add_argument("--ssid", help="Set the WiFi SSID", type=str, default="")
|
||||||
p.add_argument("--password", help="Set the WiFi password", type=str, default="")
|
p.add_argument("--password", help="Set the WiFi password", type=str, default="")
|
||||||
p.add_argument("--clear-wifi", help="Clear WiFi credentials", action="store_true")
|
p.add_argument("--clear-wifi", help="Clear WiFi credentials", action="store_true")
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
def list_boards():
|
def list_boards():
|
||||||
print("Discovered boards:")
|
print("Discovered boards:")
|
||||||
width = max((len(k) for k in BOARD_CONFIGS), default=0)
|
width = max((len(k) for k in BOARD_CONFIGS), default=0)
|
||||||
for name, path in sorted(BOARD_CONFIGS.items()):
|
for name, path in sorted(BOARD_CONFIGS.items()):
|
||||||
print(f" {name.ljust(width)} -> {os.path.relpath(path, get_root_path())}")
|
print(f" {name.ljust(width)} -> {os.path.relpath(path, get_root_path())}")
|
||||||
|
|
||||||
|
|
||||||
def _suggest_boards(partial: str) -> List[str]:
|
def _suggest_boards(partial: str) -> List[str]:
|
||||||
if not partial:
|
if not partial:
|
||||||
return []
|
return []
|
||||||
@@ -75,18 +89,23 @@ def _suggest_boards(partial: str) -> List[str]:
|
|||||||
choices = list(BOARD_CONFIGS.keys())
|
choices = list(BOARD_CONFIGS.keys())
|
||||||
return difflib.get_close_matches(partial, choices, n=5, cutoff=0.4)
|
return difflib.get_close_matches(partial, choices, n=5, cutoff=0.4)
|
||||||
|
|
||||||
|
|
||||||
def normalize_board_name(raw: Optional[str]) -> Optional[str]:
|
def normalize_board_name(raw: Optional[str]) -> Optional[str]:
|
||||||
if raw is None:
|
if raw is None:
|
||||||
return None
|
return None
|
||||||
candidate = raw.strip()
|
candidate = raw.strip()
|
||||||
if not candidate:
|
if not candidate:
|
||||||
return None
|
return None
|
||||||
candidate = candidate.replace('\\', '/').rstrip('/')
|
candidate = candidate.replace("\\", "/").rstrip("/")
|
||||||
# strip leading folders like tools/, boards/
|
# strip leading folders like tools/, boards/
|
||||||
parts = [p for p in candidate.split('/') if p not in ('.', '') and p not in ('tools', 'boards')]
|
parts = [
|
||||||
|
p
|
||||||
|
for p in candidate.split("/")
|
||||||
|
if p not in (".", "") and p not in ("tools", "boards")
|
||||||
|
]
|
||||||
if parts:
|
if parts:
|
||||||
candidate = parts[-1] if len(parts) == 1 else "_".join(parts)
|
candidate = parts[-1] if len(parts) == 1 else "_".join(parts)
|
||||||
candidate = candidate.replace('-', '_')
|
candidate = candidate.replace("-", "_")
|
||||||
# exact match
|
# exact match
|
||||||
if candidate in BOARD_CONFIGS:
|
if candidate in BOARD_CONFIGS:
|
||||||
return candidate
|
return candidate
|
||||||
@@ -131,8 +150,8 @@ def parse_config(config_file) -> dict:
|
|||||||
|
|
||||||
def handle_wifi_config(_new_config: dict, _main_config: dict, _args) -> dict:
|
def handle_wifi_config(_new_config: dict, _main_config: dict, _args) -> dict:
|
||||||
if _args.ssid:
|
if _args.ssid:
|
||||||
_new_config["CONFIG_WIFI_SSID"] = f"\"{_args.ssid}\""
|
_new_config["CONFIG_WIFI_SSID"] = f'"{_args.ssid}"'
|
||||||
_new_config["CONFIG_WIFI_PASSWORD"] = f"\"{_args.password}\""
|
_new_config["CONFIG_WIFI_PASSWORD"] = f'"{_args.password}"'
|
||||||
else:
|
else:
|
||||||
if "CONFIG_WIFI_SSID" in _main_config:
|
if "CONFIG_WIFI_SSID" in _main_config:
|
||||||
_new_config["CONFIG_WIFI_SSID"] = _main_config["CONFIG_WIFI_SSID"]
|
_new_config["CONFIG_WIFI_SSID"] = _main_config["CONFIG_WIFI_SSID"]
|
||||||
@@ -140,8 +159,8 @@ def handle_wifi_config(_new_config: dict, _main_config: dict, _args) -> dict:
|
|||||||
_new_config["CONFIG_WIFI_PASSWORD"] = _main_config["CONFIG_WIFI_PASSWORD"]
|
_new_config["CONFIG_WIFI_PASSWORD"] = _main_config["CONFIG_WIFI_PASSWORD"]
|
||||||
|
|
||||||
if _args.clear_wifi:
|
if _args.clear_wifi:
|
||||||
_new_config["CONFIG_WIFI_SSID"] = "\"\""
|
_new_config["CONFIG_WIFI_SSID"] = '""'
|
||||||
_new_config["CONFIG_WIFI_PASSWORD"] = "\"\""
|
_new_config["CONFIG_WIFI_PASSWORD"] = '""'
|
||||||
return _new_config
|
return _new_config
|
||||||
|
|
||||||
|
|
||||||
@@ -153,7 +172,9 @@ def compute_diff(_parsed_base_config: dict, _parsed_board_config: dict) -> dict:
|
|||||||
_diff[_key] = f"{OKGREEN}+{ENDC} {_parsed_board_config[_key]}"
|
_diff[_key] = f"{OKGREEN}+{ENDC} {_parsed_board_config[_key]}"
|
||||||
else:
|
else:
|
||||||
if _parsed_board_config[_key] != _parsed_base_config[_key]:
|
if _parsed_board_config[_key] != _parsed_base_config[_key]:
|
||||||
_diff[_key] = f"{OKGREEN}{_parsed_base_config[_key]}{ENDC} -> {OKBLUE}{_parsed_board_config[_key]}{ENDC}"
|
_diff[_key] = (
|
||||||
|
f"{OKGREEN}{_parsed_base_config[_key]}{ENDC} -> {OKBLUE}{_parsed_board_config[_key]}{ENDC}"
|
||||||
|
)
|
||||||
return _diff
|
return _diff
|
||||||
|
|
||||||
|
|
||||||
@@ -180,14 +201,21 @@ def main():
|
|||||||
if not os.path.isfile(get_base_config_path()):
|
if not os.path.isfile(get_base_config_path()):
|
||||||
raise SystemExit(f"Base defaults file not found: {get_base_config_path()}")
|
raise SystemExit(f"Base defaults file not found: {get_base_config_path()}")
|
||||||
|
|
||||||
print(f"{OKGREEN}Switching configuration to board:{ENDC} {OKBLUE}{normalized}{ENDC}")
|
print(
|
||||||
|
f"{OKGREEN}Switching configuration to board:{ENDC} {OKBLUE}{normalized}{ENDC}"
|
||||||
|
)
|
||||||
print(f"{OKGREEN}Using defaults from :{ENDC} {get_base_config_path()}")
|
print(f"{OKGREEN}Using defaults from :{ENDC} {get_base_config_path()}")
|
||||||
print(f"{OKGREEN}Using board config from :{ENDC} {get_board_config_path(normalized)}")
|
print(
|
||||||
|
f"{OKGREEN}Using board config from :{ENDC} {get_board_config_path(normalized)}"
|
||||||
|
)
|
||||||
|
|
||||||
with open(get_main_config_path(), "r+") as main_config:
|
with open(get_main_config_path(), "r+") as main_config:
|
||||||
parsed_main_config = parse_config(main_config)
|
parsed_main_config = parse_config(main_config)
|
||||||
|
|
||||||
with open(get_base_config_path(), "r") as base_config, open(get_board_config_path(normalized), "r") as board_config:
|
with (
|
||||||
|
open(get_base_config_path(), "r") as base_config,
|
||||||
|
open(get_board_config_path(normalized), "r") as board_config,
|
||||||
|
):
|
||||||
parsed_base_config = parse_config(base_config)
|
parsed_base_config = parse_config(base_config)
|
||||||
parsed_board_config = parse_config(board_config)
|
parsed_board_config = parse_config(board_config)
|
||||||
|
|
||||||
@@ -198,9 +226,13 @@ def main():
|
|||||||
print("---" * 5, f"{WARNING}DIFF{ENDC}", "---" * 5)
|
print("---" * 5, f"{WARNING}DIFF{ENDC}", "---" * 5)
|
||||||
diff = compute_diff(parsed_main_config, new_board_config)
|
diff = compute_diff(parsed_main_config, new_board_config)
|
||||||
if not diff:
|
if not diff:
|
||||||
print(f"{HEADER_COLOR}[DIFF]{ENDC} No changes between existing main config and {OKBLUE}{normalized}{ENDC}")
|
print(
|
||||||
|
f"{HEADER_COLOR}[DIFF]{ENDC} No changes between existing main config and {OKBLUE}{normalized}{ENDC}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print(f"{HEADER_COLOR}[DIFF]{ENDC} Keys differing (main -> new {OKBLUE}{normalized}{ENDC}):")
|
print(
|
||||||
|
f"{HEADER_COLOR}[DIFF]{ENDC} Keys differing (main -> new {OKBLUE}{normalized}{ENDC}):"
|
||||||
|
)
|
||||||
for key in sorted(diff):
|
for key in sorted(diff):
|
||||||
print(f"{HEADER_COLOR}[DIFF]{ENDC} {key} : {diff[key]}")
|
print(f"{HEADER_COLOR}[DIFF]{ENDC} {key} : {diff[key]}")
|
||||||
print("---" * 14)
|
print("---" * 14)
|
||||||
@@ -215,7 +247,10 @@ def main():
|
|||||||
main_config.write(f"{key}\n")
|
main_config.write(f"{key}\n")
|
||||||
else:
|
else:
|
||||||
print(f"{WARNING}[DRY-RUN]{ENDC} Skipping writing to files")
|
print(f"{WARNING}[DRY-RUN]{ENDC} Skipping writing to files")
|
||||||
print(f"{OKGREEN}Done. ESP-IDF is setup to build for:{ENDC} {OKBLUE}{normalized}{ENDC}")
|
print(
|
||||||
|
f"{OKGREEN}Done. ESP-IDF is setup to build for:{ENDC} {OKBLUE}{normalized}{ENDC}"
|
||||||
|
)
|
||||||
|
|
||||||
if __name__ == "__main__": # pragma: no cover
|
|
||||||
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user