fix: running ttfw tests locally hang forever while detecting ports

pull/6895/head
Fu Hanxi 2021-04-07 12:00:20 +08:00
rodzic ec01a66557
commit 7651e031cb
1 zmienionych plików z 19 dodań i 1 usunięć

Wyświetl plik

@ -369,9 +369,27 @@ class IDFDUT(DUT.SerialDUT):
with open(output_file, 'wb') as f:
f.write(content)
@staticmethod
def _sort_usb_ports(ports):
"""
Move the usb ports to the very beginning
:param ports: list of ports
:return: list of ports with usb ports at beginning
"""
usb_ports = []
rest_ports = []
for port in ports:
if 'usb' in port.lower():
usb_ports.append(port)
else:
rest_ports.append(port)
return usb_ports + rest_ports
@classmethod
def list_available_ports(cls):
ports = [x.device for x in list_ports.comports()]
# It will return other kinds of ports as well, such as ttyS* ports.
# Give the usb ports higher priority
ports = cls._sort_usb_ports([x.device for x in list_ports.comports()])
espport = os.getenv('ESPPORT')
if not espport:
# It's a little hard filter out invalid port with `serial.tools.list_ports.grep()`: