sysdevs: report paths for all devices
While a hardware UART generally won't have symlinks in the "by-path" and "by-id" folders, it is possible to configure udev to add them. In addition, adding these fields makes the schema consistent. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
6f4a0480f3
commit
145968af0f
|
@ -185,18 +185,18 @@ def find_usb_devices() -> List[Dict[str, Any]]:
|
||||||
|
|
||||||
def find_serial_devices() -> List[Dict[str, Any]]:
|
def find_serial_devices() -> List[Dict[str, Any]]:
|
||||||
serial_devs: List[Dict[str, Any]] = []
|
serial_devs: List[Dict[str, Any]] = []
|
||||||
usb_devs_by_path: Dict[str, str] = {}
|
devs_by_path: Dict[str, str] = {}
|
||||||
usb_devs_by_id: Dict[str, str] = {}
|
devs_by_id: Dict[str, str] = {}
|
||||||
usb_by_path_dir = pathlib.Path(SER_BYPTH_PATH)
|
by_path_dir = pathlib.Path(SER_BYPTH_PATH)
|
||||||
usb_by_id_dir = pathlib.Path(SER_BYID_PATH)
|
by_id_dir = pathlib.Path(SER_BYID_PATH)
|
||||||
dev_root_folder = pathlib.Path("/dev")
|
dev_root_folder = pathlib.Path("/dev")
|
||||||
if usb_by_path_dir.is_dir():
|
if by_path_dir.is_dir():
|
||||||
usb_devs_by_path = {
|
devs_by_path = {
|
||||||
dev.resolve().name: str(dev) for dev in usb_by_path_dir.iterdir()
|
dev.resolve().name: str(dev) for dev in by_path_dir.iterdir()
|
||||||
}
|
}
|
||||||
if usb_by_id_dir.is_dir():
|
if by_id_dir.is_dir():
|
||||||
usb_devs_by_id = {
|
devs_by_id = {
|
||||||
dev.resolve().name: str(dev) for dev in usb_by_id_dir.iterdir()
|
dev.resolve().name: str(dev) for dev in by_id_dir.iterdir()
|
||||||
}
|
}
|
||||||
tty_dir = pathlib.Path(TTY_PATH)
|
tty_dir = pathlib.Path(TTY_PATH)
|
||||||
for tty_path in tty_dir.iterdir():
|
for tty_path in tty_dir.iterdir():
|
||||||
|
@ -211,7 +211,10 @@ def find_serial_devices() -> List[Dict[str, Any]]:
|
||||||
"device_type": "unknown",
|
"device_type": "unknown",
|
||||||
"device_path": str(dev_root_folder.joinpath(device_name)),
|
"device_path": str(dev_root_folder.joinpath(device_name)),
|
||||||
"device_name": device_name,
|
"device_name": device_name,
|
||||||
"driver_name": driver_name
|
"driver_name": driver_name,
|
||||||
|
"path_by_hardware": devs_by_path.get(device_name),
|
||||||
|
"path_by_id": devs_by_id.get(device_name),
|
||||||
|
"usb_location": None
|
||||||
}
|
}
|
||||||
if uartclk_file.is_file() and port_file.is_file():
|
if uartclk_file.is_file() and port_file.is_file():
|
||||||
# This is a potential hardware uart. Need to
|
# This is a potential hardware uart. Need to
|
||||||
|
@ -226,13 +229,9 @@ def find_serial_devices() -> List[Dict[str, Any]]:
|
||||||
else:
|
else:
|
||||||
usb_path = device_folder.resolve()
|
usb_path = device_folder.resolve()
|
||||||
usb_location: Optional[str] = find_usb_folder(usb_path)
|
usb_location: Optional[str] = find_usb_folder(usb_path)
|
||||||
device_info["path_by_hardware"] = usb_devs_by_path.get(device_name)
|
|
||||||
device_info["path_by_id"] = usb_devs_by_id.get(device_name)
|
|
||||||
device_info["usb_location"] = None
|
|
||||||
if usb_location is not None:
|
if usb_location is not None:
|
||||||
device_info["device_type"] = "usb"
|
device_info["device_type"] = "usb"
|
||||||
device_info["usb_location"] = usb_location
|
device_info["usb_location"] = usb_location
|
||||||
|
|
||||||
serial_devs.append(device_info)
|
serial_devs.append(device_info)
|
||||||
return serial_devs
|
return serial_devs
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue