Fixed bugs

This commit is contained in:
Gino D
2022-12-29 21:15:11 +01:00
parent f428e7984d
commit f28bd0a582

View File

@@ -598,7 +598,7 @@ class Files(object):
self._pyboard.exec_(f"f.write({chunk})")
self._pyboard.exec_("f.close()")
except Exception as e:
print(' [x]')
print(' [x] > ', end='')
self.handle_traceback(e)
finally:
self._pyboard.exit_raw_repl()
@@ -632,7 +632,7 @@ class Files(object):
self._pyboard.enter_raw_repl()
output = self._pyboard.exec_(textwrap.dedent(command))
except PyboardError as e:
print(' [x]')
print(' [x] > ', end='')
self.handle_traceback(e)
finally:
self._pyboard.exit_raw_repl()
@@ -650,14 +650,14 @@ class Files(object):
import uos as os
os.remove('{filename}')
"""
print(f' {filename}', end='')
print(f'- {filename}', end='')
try:
self.__raw_repl_on = True
self._pyboard.enter_raw_repl()
self._pyboard.exec_(textwrap.dedent(command))
except Exception as e:
print(' [x]')
print(' [x] > ', end='')
self.handle_traceback(e)
finally:
self._pyboard.exit_raw_repl()
@@ -694,14 +694,15 @@ class Files(object):
os.rmdir(directory)
rmdir('{directory}')
"""
print(f' {directory}', end='')
print(f'- {directory}', end='')
try:
self.__raw_repl_on = True
self._pyboard.enter_raw_repl()
self._pyboard.exec_(textwrap.dedent(command))
except Exception as e:
print(' [x]')
if not missing_okay:
print(' [x] > ', end='')
self.handle_traceback(e)
finally:
self._pyboard.exit_raw_repl()
@@ -794,10 +795,14 @@ def upload(source: str = '', destination: str = ''):
time.sleep(.5)
elif os.path.exists(real_source):
dirpath = []
for d in os.path.dirname(destination).split('/'):
dirpath.append(d)
pico.mkdir('/'.join(dirpath), exists_okay=True)
with open(real_source, 'rb') as fh:
pico.put(destination, fh.read())
time.sleep(.5)
except Exception as e:
print(str(e))
@@ -821,8 +826,6 @@ def download(source: str = '/'):
with open(os.path.join(WATCHING_DIRECTORY, *filename.split('/')), 'wb') as fh:
fh.write(pico.get(filename))
time.sleep(.5)
except Exception as e:
print(str(e))
@@ -838,23 +841,10 @@ def contents(filename: str):
def delete(source: str, is_directory: bool = False):
try:
if is_directory:
for filename in pico.ls(directory=source, long_format=False, recursive=True):
if filename.startswith('/'):
filename = filename[1:]
if not source.endswith('/'):
source += '/'
pico.rm(filename)
try:
for filename in pico.ls(directory=source, long_format=False, recursive=True):
if filename.startswith('/'):
filename = filename[1:]
if not filename.endswith('/'):
filename += '/'
pico.rm(filename)
except:
pass
pico.rmdir(source, missing_okay=True)
else:
pico.rm(source)
except Exception as e:
@@ -906,7 +896,7 @@ def on_deleted_callback(event):
def watchdog_callback():
for source in sessions['deleted']:
delete(source)
delete(source, is_directory=source.endswith('/'))
for source in sessions['modified']:
upload(source)
@@ -956,13 +946,17 @@ try:
delete('/', is_directory=True)
case ['upl' | 'upload' | 'update', source]:
upload(source)
case ['download' | 'backup', source]:
case ['restore']:
upload('/')
case ['download' | 'transfer', source]:
download(source)
case ['backup']:
download('/')
case ['' | 'save' | 'commit']:
watchdog_callback()
case ['status' | 'staged']:
for filename in sessions['deleted']:
print('', filename)
print('-', filename)
for filename in sessions['modified']:
print('+', filename)