From: Jonatan Schlag Date: Fri, 29 Jun 2018 09:56:39 +0000 (+0200) Subject: Fix in back_at_prompt check X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=667f53f9050e8049b68a09ef5d8a229bf538d86a;p=nitsi.git Fix in back_at_prompt check When we get a line startign with '[' and the prompt is already in the buffer the pattern matches and we get wrong return code and are not back at the prompt. We now check if we have a line in the buffer and if so, we are not at the prompt. The promtp is not terminated by \n Signed-off-by: Jonatan Schlag --- diff --git a/src/nitsi/serial_connection.py b/src/nitsi/serial_connection.py index f97d94f..6e5ab31 100644 --- a/src/nitsi/serial_connection.py +++ b/src/nitsi/serial_connection.py @@ -81,7 +81,9 @@ class SerialConnection(): return data + self.con.readline() def back_at_prompt(self): + self.log.debug("Check if we are back at prompt") data = self.peek() + self.log.debug("First char in buffer is: '{}'".format(data.decode())) if not data == b"[": return False @@ -89,7 +91,12 @@ class SerialConnection(): # not the complete string size = len(self.buffer) + self.in_waiting data = self.peek(size) + self.log.debug("Data is: '{}'".format(data)) + # When we have an \n in the buffer we are not at the prompt, + # instead we still have a line in the buffer + if self.line_in_buffer(): + return False if self.back_at_prompt_pattern == None: #self.back_at_prompt_pattern = r"^\[{}@.+\]#".format(self.username) @@ -216,6 +223,8 @@ class SerialConnection(): data = self.readline() self.log_console_line(data.decode()) + self.log.debug("We get a prompt so we should be in the last line") + # We saved our exit code in data (the last line) self.log.debug(data.decode()) data = data.decode().replace("END: ", "")