Fixed bugs

This commit is contained in:
Gino D
2023-01-07 21:39:21 +01:00
parent adb9fe0c2e
commit acdfba39ad

View File

@@ -253,7 +253,7 @@ class Pyboard(object):
timeout = 0 timeout = 0
max_len = len(delimiter) max_len = len(delimiter)
while not timeout >= 100: while not timeout >= 1000:
if data.endswith(delimiter): if data.endswith(delimiter):
return data return data
elif self.serial.inWaiting() > 0: elif self.serial.inWaiting() > 0:
@@ -268,7 +268,7 @@ class Pyboard(object):
self.transfer_status() self.transfer_status()
else: else:
timeout += 1 timeout += 1
time.sleep(0.001) time.sleep(0.0001)
def boot(self): def boot(self):
data = b'' data = b''
@@ -678,7 +678,7 @@ class Picowatch(object):
print(ln) print(ln)
def upload(self, filepath: str): 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') tab.head('[ ]', 'Filename', 'Size (kb)', 'Checksum', 'Exception')
for source, size in self.internal_ls(filepath): for source, size in self.internal_ls(filepath):
@@ -738,6 +738,7 @@ class Picowatch(object):
os.remove(tempname) os.remove(tempname)
def status(self, return_output: bool = False): def status(self, return_output: bool = False):
message = ''
changes = [] changes = []
try: try:
@@ -755,24 +756,27 @@ class Picowatch(object):
changes.append((-1, filename)) changes.append((-1, filename))
except Exception as e: except Exception as e:
try: try:
print(e.output.decode('utf-8').strip()) message = e.output.decode('utf-8').strip()
except: except:
print(e.decode('utf-8').strip()) message = str(e).strip()
finally: finally:
if message:
raise Exception(message)
if return_output: if return_output:
return changes return changes
tab = Tab(4, 8, nb_columns=3) tab = Tab(4, nb_columns=2)
tab.head('[ ]', 'Status', 'Filename') tab.head('[ ]', 'Filename')
for status, filename in changes: for status, filename in changes:
if status == 1: if status == 1:
tab.line('[-]', 'EDITED', filename) tab.line('[-]', filename)
else: else:
tab.line('[+]', 'DELETED', filename) tab.line('[+]', filename)
def push(self): 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') tab.head('[ ]', 'Filename', 'Size (kb)', 'Checksum', 'Exception')
changes = self.status(return_output=True) changes = self.status(return_output=True)
@@ -787,7 +791,7 @@ class Picowatch(object):
else: else:
tab.line('[?]', filename, '', '', exception) tab.line('[?]', filename, '', '', exception)
else: else:
tab.line('[?]', filepath, '', exception) tab.line('[?]', filepath, '', '', exception)
queue = [] queue = []
@@ -802,7 +806,7 @@ class Picowatch(object):
except Exception as e: except Exception as e:
tab.line('[?]', destination, '', '', str(e)) tab.line('[?]', destination, '', '', str(e))
print('Pico board up to date.') print('Pyboard up to date.')
def compile(self, filename: str): def compile(self, filename: str):
_, error = mpy_cross.run(filename, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True).communicate() _, error = mpy_cross.run(filename, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True).communicate()
@@ -810,7 +814,7 @@ class Picowatch(object):
if error: if error:
print(error.decode('utf-8')) print(error.decode('utf-8'))
else: else:
print(f'MicroPython File from "{filename}" created!') print(f'Python file "{filename}" compile to .mpy')
def test(self, filename: str): def test(self, filename: str):
with open(os.path.join(LISTENING_TO, filename), 'r') as fh: with open(os.path.join(LISTENING_TO, filename), 'r') as fh: