Add static editor, host_ports filtering, Flask /editor and REST APIs for ports and led-cli read/write; document standalone and embedded use. Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
752 B
Python
26 lines
752 B
Python
"""Host serial port list filtering for led-tool /ports API."""
|
|
import re
|
|
|
|
# Exclude /dev/ttyS2 and higher (keep ttyS0, ttyS1; keep ttyACM*, ttyUSB*, etc.)
|
|
_TTYS_HIGH = re.compile(r"^/dev/ttyS([2-9]|[1-9]\d+)$")
|
|
|
|
|
|
def include_host_serial_device(device: str) -> bool:
|
|
return not _TTYS_HIGH.match(device or "")
|
|
|
|
|
|
def _is_na(value: str) -> bool:
|
|
return (value or "").strip().lower() in ("n/a", "na")
|
|
|
|
|
|
def include_host_serial_port(port: dict) -> bool:
|
|
if not include_host_serial_device(port.get("device", "")):
|
|
return False
|
|
if _is_na(port.get("description")) or _is_na(port.get("hwid")):
|
|
return False
|
|
return True
|
|
|
|
|
|
def filter_port_dicts(ports: list) -> list:
|
|
return [p for p in ports if include_host_serial_port(p)]
|