From 86b7159e37ad18cf8e90ccdbe00ca37b8b1b92c8 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 9 Dec 2022 12:49:06 +0100 Subject: [PATCH] dist/tools/usb-serial/ttys.py: return error on empty list If no TTY serial (matching the given filters, if any) was found, use the exit code `1`. The idea is that simple shell scripts falling back to alternative variants of a board can be used via ```.sh ttys.py --most-recent --model Fooboard --vendor Footronic || \ ttys.py --most-recent --model Barboard --vendor Bartronic ``` Just adding a regex that would accept both vendors and models would have different semantics: If both a Fooboard and a Barboard are attached, it would pick the most recently connected of both. The shell expression above would always prefer a Fooboard over a Borboard. The use case cheap Arduino clones that replace the ATmega16U2 used as USB UART bridge with cheap single purpose chips. The original ATmega16U2 has the advantage that it provides identification data unique the specific Arduino board, while the clones cannot be told apart from standalone USB UART bridges or Arduino clones of other models. Hence, we want to pick the genuine Arduino board if connected, and only fall back to matching cheap USB UART bridges if no genuine Arduino board is connected. --- dist/tools/usb-serial/ttys.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dist/tools/usb-serial/ttys.py b/dist/tools/usb-serial/ttys.py index 13bf872416..dd1bc4883e 100755 --- a/dist/tools/usb-serial/ttys.py +++ b/dist/tools/usb-serial/ttys.py @@ -176,7 +176,7 @@ def generate_filters(args): Generate filters for use in the filters_match function from the command line arguments """ - result = list() + result = [] if args.serial is not None: result.append(("serial", re.compile(r"^" + re.escape(args.serial) + r"$"))) @@ -225,6 +225,9 @@ def print_ttys(args): else: ttys = [] + if len(ttys) == 0: + sys.exit(1) + print_results(args, ttys)