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