From 2839a042be56d85eb93fe0b04c58bd9714ff624d Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sat, 10 Oct 2020 21:06:32 +0100 Subject: [PATCH] tools: wasptool: Hide the stack trace on pexpect timeout The default pexpect exception dump is verbose and potentially useful if you know how to read it... but let's handle timeouts in a friendlier way. Signed-off-by: Daniel Thompson --- tools/wasptool | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/wasptool b/tools/wasptool index 78ff83a..59f9b6f 100755 --- a/tools/wasptool +++ b/tools/wasptool @@ -279,8 +279,17 @@ if __name__ == '__main__': console = pexpect.spawn(pynus, encoding='UTF-8') if args.verbose: console.logfile = sys.stdout + else: + console.logfile = io.StringIO() + + try: + console.expect('Connect.*\(([0-9A-F:]*)\)') + except pexpect.exceptions.TIMEOUT: + print('ERROR: Cannot find suitable wasp-os device') + if not args.verbose: + print_log(console.logfile) + sys.exit(1) - console.expect('Connect.*\(([0-9A-F:]*)\)') macaddr = console.match.group(1) console.expect('Exit console using Ctrl-X') time.sleep(0.5)