Fix catch prompt from multiline issue
@@ -19,10 +19,10 @@ class ThreadedTerminal(IOConnection):
ThreadedTerminal is shell working under Pty
"""
- def __init__(self, moler_connection, data=['/bin/bash', '--norc', '--noprofile'],
- select_timeout=0.002, read_buffer_size=4096, first_prompt=None, dimensions=(100, 300)):
+ def __init__(self, moler_connection, cmd=['/bin/bash', '--norc', '--noprofile'], select_timeout=0.002,
+ read_buffer_size=4096, first_prompt=None, dimensions=(100, 300)):
super(ThreadedTerminal, self).__init__(moler_connection=moler_connection)
- self._data = data
+ self._cmd = cmd
self._select_timeout = select_timeout
self._read_buffer_size = read_buffer_size
self.dimensions = dimensions
@@ -32,11 +32,11 @@ class ThreadedTerminal(IOConnection):
if first_prompt:
self.prompt = first_prompt
else:
- self.prompt = re.compile(r'^bash-\d+\.*\d*')
+ self.prompt = r'^bash-\d+\.*\d*'
def open(self):
"""Open ThreadedTerminal connection & start thread pulling data from it."""
- self._terminal = PtyProcessUnicode.spawn(self._data, dimensions=self.dimensions)
+ self._terminal = PtyProcessUnicode.spawn(self._cmd, dimensions=self.dimensions)
done = Event()
self.pulling_thread = TillDoneThread(target=self.pull_data,
done_event=done,
@@ -56,16 +56,16 @@ class ThreadedTerminal(IOConnection):
# 1) type of line ending is a nature of connection and not each write
# 2) command can't pass any other newline since it just calls:
# self.connection.send(self.command_string)
- def send(self, data, newline="\n"):
+ def send(self, cmd, newline="\n"): # TODO: cmd --> data
"""Write data into ThreadedTerminal connection."""
- self._terminal.write(data)
+ self._terminal.write(cmd)
if newline:
self._terminal.write(newline)
def pull_data(self, pulling_done):
"""Pull data from ThreadedTerminal connection."""
- shell_operable = False
read_buffer = ""
+ shell_operable = False
while not pulling_done.is_set():
reads, _, _ = select.select([self._terminal.fd], [], [], self._select_timeout)
@@ -76,8 +76,9 @@ class ThreadedTerminal(IOConnection):
self.data_received(data)
else:
read_buffer = read_buffer + data
- if re.search(self.prompt, read_buffer):
+ if re.search(self.prompt, read_buffer, re.MULTILINE):
shell_operable = True
- read_buffer = None
+ data = re.sub(self.prompt, '', read_buffer, re.MULTILINE)
+ self.data_received(data)
except EOFError:
pulling_done.set()
