Refactored codes

This commit is contained in:
Gino D
2022-12-31 15:31:00 +01:00
parent 01523c8d04
commit 56bb67a5a2

View File

@@ -216,7 +216,7 @@ class Pyboard(object):
def __exit__(self, a, b, c): def __exit__(self, a, b, c):
self.send_ctrl_b() self.send_ctrl_b()
def __terminal(self, command: str, stream_output: bool = False, show_status: bool = True) -> Optional[str]: def __terminal(self, command: str, stream_output: bool = False) -> Optional[str]:
command = textwrap.dedent(command) command = textwrap.dedent(command)
# send input # send input
if not isinstance(command, bytes): if not isinstance(command, bytes):
@@ -236,7 +236,7 @@ class Pyboard(object):
raise Exception('Terminal: could not execute command') raise Exception('Terminal: could not execute command')
# catch output # catch output
data = self.read_until(b'\x04', stream_output=stream_output, show_status=show_status) data = self.read_until(b'\x04', stream_output=stream_output, show_status=not stream_output)
if not data: if not data:
raise Exception('Terminal: timeout waiting for first EOF reception') raise Exception('Terminal: timeout waiting for first EOF reception')
@@ -501,10 +501,10 @@ class FileSystem(object):
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
def terminal(self, command: str, stream_output: bool = False, show_status: bool = True) -> str: def terminal(self, command: str, stream_output: bool = False) -> str:
with self._pyboard as terminal: with self._pyboard as terminal:
try: try:
return terminal(command, stream_output=stream_output, show_status=show_status) return terminal(command, stream_output=stream_output)
except Exception as e: except Exception as e:
raise e raise e
@@ -616,7 +616,7 @@ class Picowatch(object):
filename = './' + filename filename = './' + filename
with open(filename, 'r') as fh: with open(filename, 'r') as fh:
self._fs.terminal(fh.read(), stream_output=True, show_status=False) self._fs.terminal(fh.read(), stream_output=True)