]> git.ipfire.org Git - nitsi.git/blobdiff - src/nitsi/serial_connection.py
Fix in back_at_prompt check
[nitsi.git] / 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: ", "")