From acdfba39ad6b2a49b26d85fb4cff56eaf512d6cb Mon Sep 17 00:00:00 2001 From: Gino D Date: Sat, 7 Jan 2023 21:39:21 +0100 Subject: [PATCH] Fixed bugs --- src/picowatch.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/picowatch.py b/src/picowatch.py index c25efd5..1fff4a3 100644 --- a/src/picowatch.py +++ b/src/picowatch.py @@ -253,7 +253,7 @@ class Pyboard(object): timeout = 0 max_len = len(delimiter) - while not timeout >= 100: + while not timeout >= 1000: if data.endswith(delimiter): return data elif self.serial.inWaiting() > 0: @@ -268,7 +268,7 @@ class Pyboard(object): self.transfer_status() else: timeout += 1 - time.sleep(0.001) + time.sleep(0.0001) def boot(self): data = b'' @@ -678,7 +678,7 @@ class Picowatch(object): print(ln) def upload(self, filepath: str): - tab = Tab(4, 30, 15, nb_columns=4) + tab = Tab(4, 30, 15, 15, nb_columns=5) tab.head('[ ]', 'Filename', 'Size (kb)', 'Checksum', 'Exception') for source, size in self.internal_ls(filepath): @@ -738,6 +738,7 @@ class Picowatch(object): os.remove(tempname) def status(self, return_output: bool = False): + message = '' changes = [] try: @@ -755,24 +756,27 @@ class Picowatch(object): changes.append((-1, filename)) except Exception as e: try: - print(e.output.decode('utf-8').strip()) + message = e.output.decode('utf-8').strip() except: - print(e.decode('utf-8').strip()) + message = str(e).strip() finally: + if message: + raise Exception(message) + if return_output: return changes - tab = Tab(4, 8, nb_columns=3) - tab.head('[ ]', 'Status', 'Filename') + tab = Tab(4, nb_columns=2) + tab.head('[ ]', 'Filename') for status, filename in changes: if status == 1: - tab.line('[-]', 'EDITED', filename) + tab.line('[-]', filename) else: - tab.line('[+]', 'DELETED', filename) + tab.line('[+]', filename) def push(self): - tab = Tab(4, 30, 15, nb_columns=4) + tab = Tab(4, 30, 15, 15, nb_columns=5) tab.head('[ ]', 'Filename', 'Size (kb)', 'Checksum', 'Exception') changes = self.status(return_output=True) @@ -787,7 +791,7 @@ class Picowatch(object): else: tab.line('[?]', filename, '', '', exception) else: - tab.line('[?]', filepath, '', exception) + tab.line('[?]', filepath, '', '', exception) queue = [] @@ -802,7 +806,7 @@ class Picowatch(object): except Exception as e: tab.line('[?]', destination, '', '', str(e)) - print('Pico board up to date.') + print('Pyboard up to date.') def compile(self, filename: str): _, error = mpy_cross.run(filename, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True).communicate() @@ -810,7 +814,7 @@ class Picowatch(object): if error: print(error.decode('utf-8')) else: - print(f'MicroPython File from "{filename}" created!') + print(f'Python file "{filename}" compile to .mpy') def test(self, filename: str): with open(os.path.join(LISTENING_TO, filename), 'r') as fh: