Print tabulation added
This commit is contained in:
@@ -37,7 +37,9 @@ from typing import Dict, List, Optional, Tuple, Union
|
||||
|
||||
|
||||
BUFFER_SIZE: int = 126
|
||||
PRINT_STRPAD = '\t\t =>'
|
||||
|
||||
def strpad(text: str, length: int = 30) -> str:
|
||||
return text + ' ' * (length - len(text))
|
||||
|
||||
|
||||
class Telnet:
|
||||
@@ -187,7 +189,7 @@ class Pyboard(object):
|
||||
self.loading()
|
||||
else:
|
||||
timeout += 1
|
||||
time.sleep(0.001)
|
||||
time.sleep(0.0001)
|
||||
|
||||
def __enter__(self):
|
||||
self.send_ctrl_c()
|
||||
@@ -230,7 +232,7 @@ class Pyboard(object):
|
||||
self.loading()
|
||||
|
||||
self.serial.write(command[i: min(i + BUFFER_SIZE, len(command))])
|
||||
time.sleep(0.001)
|
||||
time.sleep(0.0001)
|
||||
|
||||
if not self.read_until(self.send_ok()):
|
||||
raise Exception('Terminal: could not execute command')
|
||||
@@ -526,17 +528,21 @@ class Picowatch(object):
|
||||
status, output, exception = self._fs.ls(remote)
|
||||
|
||||
if status:
|
||||
print('-' * 60)
|
||||
print('[ ]', strpad('filename'), 'size|exception')
|
||||
print('-' * 60)
|
||||
|
||||
for name, size in output:
|
||||
if size == -1:
|
||||
print('[*]', name[1:])
|
||||
print('[*]', strpad(name[1:]), '-')
|
||||
else:
|
||||
print('[.]', name[1:], f'({size}b)')
|
||||
print('[*]', strpad(name[1:]), f'{size}b')
|
||||
else:
|
||||
print('[?]', remote, PRINT_STRPAD, exception)
|
||||
print('[?]', strpad(remote), exception)
|
||||
|
||||
def contents(self, remote: str):
|
||||
try:
|
||||
content, checksum = self._fs.get(remote)
|
||||
content, _ = self._fs.get(remote)
|
||||
|
||||
for ln in content.decode('utf-8').split('\n'):
|
||||
print(ln)
|
||||
@@ -562,12 +568,16 @@ class Picowatch(object):
|
||||
|
||||
elif os.path.exists(local):
|
||||
queue.append((local, filepath))
|
||||
|
||||
print('-' * 60)
|
||||
print('[ ]', strpad('filename'), 'checksum|exception')
|
||||
print('-' * 60)
|
||||
|
||||
for filename, remote in queue:
|
||||
try:
|
||||
print('[↑]', filename, PRINT_STRPAD, self._fs.upload(filename, remote))
|
||||
print('[↑]', strpad(filename), self._fs.upload(filename, remote))
|
||||
except Exception as e:
|
||||
print('[?]', filename, PRINT_STRPAD, str(e))
|
||||
print('[?]', strpad(filename), str(e))
|
||||
|
||||
def download(self, filepath: str):
|
||||
if filepath.startswith('.'):
|
||||
@@ -576,6 +586,10 @@ class Picowatch(object):
|
||||
status, output, exception = self._fs.ls(filepath)
|
||||
|
||||
if status:
|
||||
print('-' * 60)
|
||||
print('[ ]', strpad('filename'), 'checksum|exception')
|
||||
print('-' * 60)
|
||||
|
||||
for remote, size in output:
|
||||
if size == -1:
|
||||
os.makedirs(f'.{remote}', 777, exist_ok=True)
|
||||
@@ -585,25 +599,29 @@ class Picowatch(object):
|
||||
|
||||
if not size == -1:
|
||||
try:
|
||||
print('[↓]', local, PRINT_STRPAD, self._fs.download(remote, local))
|
||||
print('[↓]', strpad(local), self._fs.download(remote, local))
|
||||
except Exception as e:
|
||||
print('[?]', local, PRINT_STRPAD, str(e))
|
||||
print('[?]', strpad(local), str(e))
|
||||
else:
|
||||
print('[?]', filepath, PRINT_STRPAD, exception)
|
||||
print('[?]', strpad(filepath), exception)
|
||||
|
||||
def delete(self, filepath: str):
|
||||
status, output, exception = self._fs.rm(filepath)
|
||||
|
||||
if status:
|
||||
print('-' * 60)
|
||||
print('[ ]', strpad('filename'), 'exception')
|
||||
print('-' * 60)
|
||||
|
||||
for remote, checked, message in output:
|
||||
local = f'.{remote}'
|
||||
|
||||
if checked:
|
||||
print('[-]', local)
|
||||
print('[-]', strpad(local))
|
||||
else:
|
||||
print('[?]', local, PRINT_STRPAD, message)
|
||||
print('[?]', strpad(local), message)
|
||||
else:
|
||||
print('[?]', filepath, PRINT_STRPAD, exception)
|
||||
print('[?]', strpad(filepath), exception)
|
||||
|
||||
def launch(self, filepath: str):
|
||||
self._fs.launch(filepath)
|
||||
@@ -686,46 +704,51 @@ picowatch.interupt()
|
||||
# try:
|
||||
while True:
|
||||
try:
|
||||
message = input('>>> ').strip()
|
||||
unmessage = input('>>> ').strip()
|
||||
|
||||
match message.split(' '):
|
||||
case ['0' | 'exit']:
|
||||
sys.exit()
|
||||
case ['reboot' | 'reset']:
|
||||
picowatch.terminal('help()')
|
||||
case ['ls' | 'stat', *source]:
|
||||
picowatch.listing(source[0] if source else '/')
|
||||
case ['cat' | 'open' | 'contents', source]:
|
||||
picowatch.contents(source)
|
||||
case ['del' | 'rm' | 'delete' | 'remove', source]:
|
||||
picowatch.delete(source)
|
||||
case ['format']:
|
||||
picowatch.delete('/')
|
||||
case ['upl' | 'upload' | 'update', source]:
|
||||
picowatch.upload(source)
|
||||
case ['restore']:
|
||||
picowatch.upload('/')
|
||||
case ['download' | 'transfer', source]:
|
||||
picowatch.download(source)
|
||||
case ['backup']:
|
||||
picowatch.download('/')
|
||||
# case ['' | 'save' | 'commit']:
|
||||
# watchdog_callback()
|
||||
# case ['status' | 'staged']:
|
||||
# for filename in sessions['deleted']:
|
||||
# print('-', filename)
|
||||
# for filename in sessions['modified']:
|
||||
# print('+', filename)
|
||||
# case ['cancel' | 'unstaged']:
|
||||
# sessions['deleted'] = set()
|
||||
# sessions['modified'] = set()
|
||||
case ['watch' | 'test', filename]:
|
||||
picowatch.watch(filename)
|
||||
case _:
|
||||
if message.startswith('./'):
|
||||
picowatch.launch(message[2:])
|
||||
elif message:
|
||||
print(f'"{message}" is not recognized.')
|
||||
for message in unmessage.split('&'):
|
||||
match message.strip().split(' '):
|
||||
case ['0' | 'exit']:
|
||||
sys.exit()
|
||||
case ['reboot' | 'reset']:
|
||||
picowatch.terminal('help()')
|
||||
case ['ls' | 'stat', *source]:
|
||||
picowatch.listing(source[0] if source else '/')
|
||||
case ['cat' | 'open' | 'contents', source]:
|
||||
picowatch.contents(source)
|
||||
case ['del' | 'rm' | 'delete' | 'remove', source]:
|
||||
picowatch.delete(source)
|
||||
case ['format']:
|
||||
picowatch.delete('/')
|
||||
case ['upl' | 'upload' | 'update', source]:
|
||||
picowatch.upload(source)
|
||||
case ['restore']:
|
||||
picowatch.upload('/')
|
||||
case ['download' | 'transfer', source]:
|
||||
picowatch.download(source)
|
||||
case ['backup']:
|
||||
picowatch.download('/')
|
||||
# case ['' | 'save' | 'commit']:
|
||||
# watchdog_callback()
|
||||
# case ['status' | 'staged']:
|
||||
# for filename in sessions['deleted']:
|
||||
# print('-', filename)
|
||||
# for filename in sessions['modified']:
|
||||
# print('+', filename)
|
||||
# case ['cancel' | 'unstaged']:
|
||||
# sessions['deleted'] = set()
|
||||
# sessions['modified'] = set()
|
||||
case ['!', 'watch' | 'test', filename]:
|
||||
picowatch.watch(filename)
|
||||
case ['!']:
|
||||
picowatch.watch('main.py')
|
||||
case ['!!']:
|
||||
picowatch.launch('main.py')
|
||||
case _:
|
||||
if message.startswith('./'):
|
||||
picowatch.launch(message[2:])
|
||||
elif message:
|
||||
print(f'"{message}" is not recognized.')
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
# except KeyboardInterrupt:
|
||||
|
||||
Reference in New Issue
Block a user