From 78952468c8d82abd1a97d58515da11d348db91e7 Mon Sep 17 00:00:00 2001 From: Thomas Friebel Date: Sun, 25 Sep 2022 09:46:51 +0200 Subject: [PATCH 1/4] Remove commented debug prints The same information is logged in the called functions, so even uncommenting the debug prints would not add value. --- rshell/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/rshell/main.py b/rshell/main.py index 7a810d9..1dff1dc 100755 --- a/rshell/main.py +++ b/rshell/main.py @@ -1388,11 +1388,9 @@ def connect(port, baud=115200, user='micro', password='python', wait=0): """Tries to connect automagically via network or serial.""" try: ip_address = socket.gethostbyname(port) - #print('Connecting to ip', ip_address) connect_telnet(port, ip_address, user=user, password=password) except (socket.gaierror, ValueError): # Doesn't look like a hostname or IP-address, assume its a serial port - #print('connecting to serial', port) connect_serial(port, baud=baud, wait=wait) From f75c85f6670b32c421c9d357a005000c52956fc5 Mon Sep 17 00:00:00 2001 From: Thomas Friebel Date: Sun, 25 Sep 2022 09:11:43 +0200 Subject: [PATCH 2/4] Print buffer size only in debug mode The buffer size is an implementation detail that should just work out of the box and does not add value to the average user. Only print it in debug mode. --- rshell/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rshell/main.py b/rshell/main.py index 1dff1dc..d9ff69e 100755 --- a/rshell/main.py +++ b/rshell/main.py @@ -3046,7 +3046,8 @@ def real_main(): BUFFER_SIZE = USB_BUFFER_SIZE else: BUFFER_SIZE = UART_BUFFER_SIZE - QUIET or print('Using buffer-size of', BUFFER_SIZE) + if DEBUG: + print('Using buffer-size of', BUFFER_SIZE) try: connect(args.port, baud=args.baud, wait=args.wait, user=args.user, password=args.password) except DeviceError as err: From 9d0c7999f6c25e8af856f6a513012b1136160121 Mon Sep 17 00:00:00 2001 From: Thomas Friebel Date: Sun, 25 Sep 2022 09:06:14 +0200 Subject: [PATCH 3/4] Harmonize connection log messages Most log messages follow the same format: Operation ... result Modify the two message accordingly that do not follow that format yet. --- rshell/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rshell/main.py b/rshell/main.py index d9ff69e..dc9eb09 100755 --- a/rshell/main.py +++ b/rshell/main.py @@ -1413,7 +1413,7 @@ def connect_telnet(name, ip_address=None, user='micro', password='python'): def connect_serial(port, baud=115200, wait=0): """Connect to a MicroPython board via a serial port.""" if not QUIET: - print('Connecting to %s (buffer-size %d)...' % (port, BUFFER_SIZE)) + print('Connecting to %s (buffer-size %d) ...' % (port, BUFFER_SIZE)) try: dev = DeviceSerial(port, baud, wait) except DeviceError as err: @@ -1729,7 +1729,7 @@ def __init__(self, port, baud, wait): QUIET or sys.stdout.write('\n') # Send Control-C followed by CR until we get a >>> prompt - QUIET or print('Trying to connect to REPL ', end='', flush=True) + QUIET or print('Trying to connect to REPL ...', end='', flush=True) connected = False for _ in range(20): pyb.serial.write(b'\x03\r') From dd06a390e670b735b2ffd92157c69052065d4553 Mon Sep 17 00:00:00 2001 From: Thomas Friebel Date: Sun, 25 Sep 2022 09:45:57 +0200 Subject: [PATCH 4/4] Only add directories to root dir list --- rshell/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rshell/main.py b/rshell/main.py index dc9eb09..a2e7550 100755 --- a/rshell/main.py +++ b/rshell/main.py @@ -792,6 +792,13 @@ def listdir(dirname): return os.listdir(dirname) +def list_root_dirs(): + """Returns a list of filenames contained in the named directory.""" + import os + S_IFDIR = 0o40000 + return [entry for entry in os.listdir('/') if os.stat('/' + entry)[0] & S_IFDIR] + + def listdir_matches(match): """Returns a list of filenames contained in the named directory. Only filenames which start with `match` will be returned. @@ -1512,7 +1519,7 @@ def __init__(self, pyb): if not unhexlify_exists: raise ShellError('rshell needs MicroPython firmware with ubinascii.unhexlify') QUIET or print('Retrieving root directories ... ', end='', flush=True) - self.root_dirs = ['/{}/'.format(dir) for dir in self.remote_eval(listdir, '/')] + self.root_dirs = ['/{}/'.format(dir) for dir in self.remote_eval(list_root_dirs)] QUIET or print(' '.join(self.root_dirs)) QUIET or print('Setting time ... ', end='', flush=True) now = self.sync_time()