Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ authors = [
]
dynamic = ["readme", "version"]

dependencies = ["tomlkit", "rich", "click", "rich-click", "humanize", "platformdirs", "readchar"]
dependencies = ["tomlkit", "rich", "click", "rich-click", "humanize", "platformdirs", "readchar", "minicom"]

[project.urls]
"Source code" = "https://github.com/dhrosa/circuitpython_tool"
Expand Down
36 changes: 30 additions & 6 deletions src/circuitpython_tool/hw/udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,28 @@ def all() -> Iterator["UsbDevice"]:
continue
yield UsbDevice(
path=Path(devname),
vendor_id=properties["ID_USB_VENDOR_ID"],
vendor=properties["ID_USB_VENDOR"],
model_id=properties["ID_USB_MODEL_ID"],
model=properties["ID_USB_MODEL"],
# not all devices have all properties, so we fall back to alt names, which
# prevents a traceback from the missing property.
vendor_id=get_property(
properties, "ID_USB_VENDOR_ID", "ID_VENDOR_ID"
),
vendor=get_property(
properties, "ID_USB_VENDOR", "ID_VENDOR", "ID_VENDOR_FROM_DATABASE"
),
model_id=get_property(properties, "ID_USB_MODEL_ID", "ID_MODEL_ID"),
model=get_property(
properties, "ID_USB_MODEL", "ID_MODEL", "ID_MODEL_FROM_DATABASE"
),
serial=(
properties.get("ID_USB_SERIAL_SHORT") or properties["ID_USB_SERIAL"]
properties.get("ID_USB_SERIAL_SHORT")
or get_property(
properties,
"ID_USB_SERIAL",
"ID_SERIAL_SHORT",
"ID_SERIAL",
)
),
is_tty=properties["SUBSYSTEM"] == "tty",
is_tty=properties.get("SUBSYSTEM") == "tty",
partition_label=properties.get("ID_FS_LABEL"),
)

Expand All @@ -78,3 +92,13 @@ def parse_properties(entry: str) -> dict[str, str]:
key, value = line.split("=", maxsplit=1)
properties[key] = value
return properties


def get_property(
properties: dict[str, str], *keys: str, default: str = "unknown"
) -> str:
"""Return the first present property from `keys`, falling back to `default`."""
for key in keys:
if value := properties.get(key):
return value
return default
151 changes: 151 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.