summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2021-09-10 18:52:11 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2021-09-10 20:17:57 (GMT)
commit2a3ffad07d62fcca7fa8dd3fe387f4377b44d3e4 (patch)
tree166ab9efdf3302e30ff5b089481a75e617a11744 /tools
parenta7c8939737e669a48fd2c8ba2b1db6d945d22932 (diff)
wasptool: Automatically create directories during upload
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/wasptool24
1 files changed, 16 insertions, 8 deletions
diff --git a/tools/wasptool b/tools/wasptool
index 05a4486..39d32f3 100755
--- a/tools/wasptool
+++ b/tools/wasptool
@@ -287,9 +287,14 @@ def handle_binary_upload(c, fname, tname):
if not tname:
tname = os.path.basename(fname)
+ else:
+ dname = os.path.dirname(tname)
+ if dname:
+ c.run_command('import os')
+ c.sendline(f'os.mkdir("{dname}")')
+ c.run_command('del os')
- c.sendline(f'f = open("{tname}", "wb")')
- c.expect('>>> ')
+ c.run_command(f'f = open("{tname}", "wb")')
# Absorb the file to be uploaded
with open(fname, 'rb') as f:
@@ -303,20 +308,23 @@ def handle_binary_upload(c, fname, tname):
# Send the data
for i in pbar(range(0, chunksz*nchunks, chunksz), verbose):
- c.sendline(f'f.write({repr(data[i:i+chunksz])})')
- c.expect('>>> ')
+ c.run_command(f'f.write({repr(data[i:i+chunksz])})')
if lastchunk:
- c.sendline(f'f.write({repr(data[-lastchunk:])})')
- c.expect('>>> ')
+ c.run_command(f'f.write({repr(data[-lastchunk:])})')
- c.sendline('f.close()')
- c.expect('>>> ')
+ c.run_command('f.close()')
def handle_upload(c, fname, tname):
verbose = bool(c.logfile)
if not tname:
tname = os.path.basename(fname)
+ else:
+ dname = os.path.dirname(tname)
+ if dname:
+ c.run_command('import os')
+ c.sendline(f'os.mkdir("{dname}")')
+ c.run_command('del os')
c.run_command('from shell import upload')