From e79625685dea9d4dd0b99a071c2f89b23fb6e541 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sun, 10 Jan 2021 14:49:36 +0000 Subject: [PATCH] wasptool: Allow files to be renamed during an upload For example: ./tools/wasptool --upload docs/main/chrono.py --as main.py Signed-off-by: Daniel Thompson --- tools/wasptool | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/wasptool b/tools/wasptool index 30d020e..4b5b4d9 100755 --- a/tools/wasptool +++ b/tools/wasptool @@ -207,10 +207,13 @@ def check_rtc(c): c.expect('>>> ') -def handle_binary_upload(c, fname): +def handle_binary_upload(c, fname, tname): verbose = bool(c.logfile) - c.sendline(f'f = open("{os.path.basename(fname)}", "wb")') + if not tname: + tname = os.path.basename(fname) + + c.sendline(f'f = open("{tname}", "wb")') c.expect('>>> ') # Absorb the file to be uploaded @@ -234,9 +237,12 @@ def handle_binary_upload(c, fname): c.sendline('f.close()') c.expect('>>> ') -def handle_upload(c, fname): +def handle_upload(c, fname, tname): verbose = bool(c.logfile) + if not tname: + tname = os.path.basename(fname) + c.sendline('from shell import upload') c.expect('>>> ') @@ -244,7 +250,7 @@ def handle_upload(c, fname): if not verbose: print(f'Uploading {fname}:') - c.sendline(f'upload("{os.path.basename(fname)}")') + c.sendline(f'upload("{tname}")') c.expect('=== ') paste(c, f, verbose) c.send('\x04') @@ -254,6 +260,8 @@ def handle_upload(c, fname): if __name__ == '__main__': parser = argparse.ArgumentParser( description='Wasp-os command and control client') + parser.add_argument('--as', dest='upload_as', default=None, + help="Filename to use on the target (e.g. wasptool --upload docs/main/chrono.py --as main.py") parser.add_argument('--bootloader', action='store_true', help="Reboot into the bootloader mode for OTA update") parser.add_argument('--binary', action='store_true', @@ -326,9 +334,9 @@ if __name__ == '__main__': if args.upload: if args.binary: - handle_binary_upload(console, args.upload) + handle_binary_upload(console, args.upload, args.upload_as) else: - handle_upload(console, args.upload) + handle_upload(console, args.upload, args.upload_as) if args.console: console.close()