From 62bfa793247930f7033bfeff26b0817477a61ad5 Mon Sep 17 00:00:00 2001 From: Obijuan Date: Tue, 5 Mar 2024 08:56:00 +0100 Subject: [PATCH] scons: _check_ftdi(): refactor --- apio/managers/scons.py | 11 ++++++++--- apio/managers/system.py | 5 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apio/managers/scons.py b/apio/managers/scons.py index e4679cd9..d79bfc20 100644 --- a/apio/managers/scons.py +++ b/apio/managers/scons.py @@ -675,12 +675,17 @@ def _check_ftdi(board, board_data, ext_ftdi_id): desc_pattern = f"^{board_desc}.*$" # Match the discovered FTDI chips - ftdi_devices = System().get_ftdi_devices() - if len(ftdi_devices) == 0: + # -- Get the list of the connected FTDI devices + # -- (execute the command "lsftdi" from the apio System module) + system = System() + connected_devices = system.get_ftdi_devices() + + if len(connected_devices) == 0: # Board not available raise AttributeError("board " + board + " not available") - for ftdi_device in ftdi_devices: + + for ftdi_device in connected_devices: index = ftdi_device.get("index") # ftdi device indices can start at zero if ext_ftdi_id is not None and ext_ftdi_id != index: diff --git a/apio/managers/system.py b/apio/managers/system.py index cf356f08..00fc6522 100644 --- a/apio/managers/system.py +++ b/apio/managers/system.py @@ -123,7 +123,7 @@ def get_ftdi_devices(self) -> list: This list is obtained by running the "lsftdi" command * OUTPUT: A list of objects with the FTDI devices - Ex. [{'index': '0', 'manufacturer': 'AlhambraBits', + Ex. [{'index': '0', 'manufacturer': 'AlhambraBits', 'description': 'Alhambra II v1.0A - B07-095'}] It raises an exception in case of not being able to @@ -141,7 +141,7 @@ def get_ftdi_devices(self) -> list: # -- Get the list of the ftdi devices. It is read # -- from the command stdout - # -- Ex: [{'index': '0', 'manufacturer': 'AlhambraBits', + # -- Ex: [{'index': '0', 'manufacturer': 'AlhambraBits', # -- 'description': 'Alhambra II v1.0A - B07-095'}] ftdi_devices = self._parse_ftdi_devices(result["out"]) @@ -152,7 +152,6 @@ def get_ftdi_devices(self) -> list: # -- for reading the ftdi devices raise RuntimeError("Error executing lsftdi") - def _run_command(self, command: str, silent=False) -> dict: """Execute the given system command * INPUT: