Send files from one computer to another! A graphical interface for magic-wormhole https://magic-wormhole.readthedocs.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

47 lines
1.7 KiB

from subprocess import PIPE
from trio import TASK_STATUS_IGNORED, CancelScope, open_process, run_process
from dropship.logger import log
async def wormhole_send(fpath, parent, task_status=TASK_STATUS_IGNORED):
"""Run `wormhole send` on a local file path."""
with CancelScope() as scope:
command = ["wormhole", "send", fpath]
process = await open_process(command, stderr=PIPE, stdout=PIPE)
output = await process.stderr.receive_some()
#this is some nasty hacky shit
async for i in process.stderr:
if b"On the other computer" in i:
output = i
break
code = output.decode().split()[-1]
task_status.started((code, scope,))
log.info(f"wormhole_send: now waiting for other side ({code})")
await process.wait()
log.info(f"wormhole_send: succesfully transfered ({code})")
if scope.cancel_called:
process.terminate()
log.info(f"wormhole_send: succesfully terminated process ({code})")
parent._remove_pending_transfer(code)
async def wormhole_recv(code, parent, task_status=TASK_STATUS_IGNORED):
"""Run `wormhole receive` on a pending transfer code."""
with CancelScope() as scope:
command = ["wormhole", "receive", "--accept-file", code]
process = await open_process(command, stderr=PIPE)
task_status.started((scope,))
log.info(f"wormhole_recv: now starting receiving process ({code})")
await process.wait()
log.info(f"wormhole_recv: succesfully received ({code})")
if scope.cancel_called:
process.terminate()
log.info(f"wormhole_recv: succesfully terminated process ({code})")
parent._remove_pending_transfer(code)