From 0c70d3bc62a3cb58c4e411f1d64ff08691ccb1f4 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 14 Mar 2019 10:47:13 +0100 Subject: runner: fake peek support in ShellMonitor --- lib/runner.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/runner.py') diff --git a/lib/runner.py b/lib/runner.py index 87c41c5..fa08c01 100644 --- a/lib/runner.py +++ b/lib/runner.py @@ -84,7 +84,6 @@ class SerialMonitor: Communication uses no parity, no flow control, and one stop bit. Data collection starts immediately. """ - self.peek = peek self.ser = serial.serial_for_url(port, do_not_open=True) self.ser.baudrate = baud self.ser.parity = 'N' @@ -120,13 +119,14 @@ class SerialMonitor: class ShellMonitor: """SerialMonitor runs a program and captures its output for a specific amount of time.""" - def __init__(self, script: str): + def __init__(self, script: str, peek = None): """ Create a new ShellMonitor object. Does not start execution and monitoring yet. """ self.script = script + self.peek = peek def run(self, timeout: int = 4) -> list: """ @@ -134,9 +134,13 @@ class ShellMonitor: stderr and return status are discarded at the moment. """ + if type(timeout) != int: + raise ValueError('timeout argument must be int') res = subprocess.run(['timeout', '{:d}s'.format(timeout), self.script], stdout = subprocess.PIPE, stderr = subprocess.PIPE, universal_newlines = True) + if self.peek: + print(res.stdout) return res.stdout.split('\n') def monitor(self): -- cgit v1.2.3