From 3bf114cf48513b8857bd38417ab2083871d73d3e Mon Sep 17 00:00:00 2001 From: Sascha Bischoff Date: Mon, 2 Nov 2015 11:42:33 +0000 Subject: [PATCH] Gem5Device: Improve shell command matching - Replace ugly while True loop with a simple regex substitution achieving the same thing. This is required to match the command in the shell output when the command wraps around due to the length of the command. --- wlauto/devices/android/gem5/__init__.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/wlauto/devices/android/gem5/__init__.py b/wlauto/devices/android/gem5/__init__.py index b95e12b3..75862e02 100644 --- a/wlauto/devices/android/gem5/__init__.py +++ b/wlauto/devices/android/gem5/__init__.py @@ -717,26 +717,12 @@ class Gem5Device(AndroidDevice): while command_index == -1: if conn.prompt(): output = re.sub(r' \r([^\n])', r'\1', conn.before) + output = re.sub(r'[\b]', r'', output) + # Deal with line wrapping + output = re.sub(r'[\r].+?<', r'', output) command_index = output.find(command) - # The command was probably too long and wrapped. This bit of - # code is a total hack! - if command_index == -1: - # We need to remove the backspace characters! - output = re.sub(r'[\b]', r'', output) - while True: - first_cr = output.find('\r') - first_lt = output.find('<') - if first_cr == -1 or first_lt == -1: - break - if first_cr < first_lt: - new_output = output[:first_cr] - new_output += output[first_lt + 1:] - output = new_output - command_index = output.find(command) - else: - break - # If we STILL have -1, then we cannot match the command, but the + # If we have -1, then we cannot match the command, but the # prompt has returned. Hence, we have a bit of an issue. We # warn, and return the whole output. if command_index == -1: