tools/mpremote: Allow + terminator for fs commands.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2022-08-18 12:32:10 +10:00 committed by Damien George
parent 8f4c108025
commit a311e9e3d4
2 changed files with 31 additions and 10 deletions

View File

@ -30,6 +30,9 @@ For REPL access, running ``mpremote`` without any arguments is usually all that
is needed. ``mpremote`` also supports a set of commands given at the command
line which will perform various actions on remote MicroPython devices.
For commands that support multiple arguments (e.g. a list of files), the
argument list can be terminated with ``+``.
The full list of supported commands are:
- connect to a specified device via a device-name shortcut:
@ -248,3 +251,5 @@ Examples
mpremote cp main.py :
mpremote cp -r dir/ :
mpremote cp a.py b.py : + repl

View File

@ -300,6 +300,19 @@ def show_progress_bar(size, total_size):
)
# Get all args up to the terminator ("+").
# The passed args will be updated with these ones removed.
def get_fs_args(args):
n = 0
for src in args:
if src == "+":
break
n += 1
fs_args = args[:n]
args[:] = args[n + 1 :]
return fs_args
def do_filesystem(pyb, args):
def _list_recursive(files, path):
if os.path.isdir(path):
@ -308,16 +321,18 @@ def do_filesystem(pyb, args):
else:
files.append(os.path.split(path))
# Don't be verbose when using cat, so output can be redirected to something.
verbose = args[0] != "cat"
fs_args = get_fs_args(args)
if args[0] == "cp" and args[1] == "-r":
args.pop(0)
args.pop(0)
assert args[-1] == ":"
args.pop()
# Don't be verbose when using cat, so output can be redirected to something.
verbose = fs_args[0] != "cat"
if fs_args[0] == "cp" and fs_args[1] == "-r":
fs_args.pop(0)
fs_args.pop(0)
assert fs_args[-1] == ":"
fs_args.pop()
src_files = []
for path in args:
for path in fs_args:
_list_recursive(src_files, path)
known_dirs = {""}
pyb.exec_("import uos")
@ -335,8 +350,9 @@ def do_filesystem(pyb, args):
verbose=verbose,
)
else:
pyboard.filesystem_command(pyb, args, progress_callback=show_progress_bar, verbose=verbose)
args.clear()
pyboard.filesystem_command(
pyb, fs_args, progress_callback=show_progress_bar, verbose=verbose
)
def do_repl_main_loop(pyb, console_in, console_out_write, *, code_to_inject, file_to_inject):