]> git.ipfire.org Git - nitsi.git/commitdiff
Fix in back_at_prompt check
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Fri, 29 Jun 2018 09:56:39 +0000 (11:56 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Fri, 29 Jun 2018 09:56:39 +0000 (11:56 +0200)
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 <jonatan.schlag@ipfire.org>
src/nitsi/serial_connection.py

index f97d94f45b1d57d9a30e5f48a46943f518317971..6e5ab31b84789b3e8503443868a2ab65b08b0525 100644 (file)
@@ -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: ", "")