wasptool: Automatically create directories during upload
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
parent
a7c8939737
commit
2a3ffad07d
1 changed files with 16 additions and 8 deletions
|
@ -287,9 +287,14 @@ def handle_binary_upload(c, fname, tname):
|
||||||
|
|
||||||
if not tname:
|
if not tname:
|
||||||
tname = os.path.basename(fname)
|
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.run_command(f'f = open("{tname}", "wb")')
|
||||||
c.expect('>>> ')
|
|
||||||
|
|
||||||
# Absorb the file to be uploaded
|
# Absorb the file to be uploaded
|
||||||
with open(fname, 'rb') as f:
|
with open(fname, 'rb') as f:
|
||||||
|
@ -303,20 +308,23 @@ def handle_binary_upload(c, fname, tname):
|
||||||
|
|
||||||
# Send the data
|
# Send the data
|
||||||
for i in pbar(range(0, chunksz*nchunks, chunksz), verbose):
|
for i in pbar(range(0, chunksz*nchunks, chunksz), verbose):
|
||||||
c.sendline(f'f.write({repr(data[i:i+chunksz])})')
|
c.run_command(f'f.write({repr(data[i:i+chunksz])})')
|
||||||
c.expect('>>> ')
|
|
||||||
if lastchunk:
|
if lastchunk:
|
||||||
c.sendline(f'f.write({repr(data[-lastchunk:])})')
|
c.run_command(f'f.write({repr(data[-lastchunk:])})')
|
||||||
c.expect('>>> ')
|
|
||||||
|
|
||||||
c.sendline('f.close()')
|
c.run_command('f.close()')
|
||||||
c.expect('>>> ')
|
|
||||||
|
|
||||||
def handle_upload(c, fname, tname):
|
def handle_upload(c, fname, tname):
|
||||||
verbose = bool(c.logfile)
|
verbose = bool(c.logfile)
|
||||||
|
|
||||||
if not tname:
|
if not tname:
|
||||||
tname = os.path.basename(fname)
|
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')
|
c.run_command('from shell import upload')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue