use croc as a backend
This commit is contained in:
parent
393120f3f1
commit
2d06ed6a94
47
dropship/croc.py
Normal file
47
dropship/croc.py
Normal file
@ -0,0 +1,47 @@
|
||||
from subprocess import PIPE
|
||||
|
||||
from trio import TASK_STATUS_IGNORED, CancelScope, open_process, run_process
|
||||
|
||||
from dropship.logger import log
|
||||
|
||||
|
||||
async def croc_send(fpath, parent, task_status=TASK_STATUS_IGNORED):
|
||||
"""Run `croc send` on a local file path."""
|
||||
with CancelScope() as scope:
|
||||
command = ["croc", "send", fpath]
|
||||
process = await open_process(command, stderr=PIPE)
|
||||
|
||||
#output = await process.stderr.receive_some()
|
||||
#this is some nasty hacky shit
|
||||
async for i in process.stderr:
|
||||
if b"Code is:" in i:
|
||||
output = i
|
||||
break
|
||||
code = output.decode().split()[-1]
|
||||
task_status.started((code, scope,))
|
||||
log.info(f"croc_send: now waiting for other side ({code})")
|
||||
await process.wait()
|
||||
log.info(f"croc_send: succesfully transfered ({code})")
|
||||
|
||||
if scope.cancel_called:
|
||||
process.terminate()
|
||||
log.info(f"croc_send: succesfully terminated process ({code})")
|
||||
|
||||
parent._remove_pending_transfer(code)
|
||||
|
||||
|
||||
async def croc_recv(code, parent, task_status=TASK_STATUS_IGNORED):
|
||||
"""Run `croc receive` on a pending transfer code."""
|
||||
with CancelScope() as scope:
|
||||
command = ["croc", "--yes", code]
|
||||
process = await open_process(command, stderr=PIPE)
|
||||
task_status.started((scope,))
|
||||
log.info(f"croc_recv: now starting receiving process ({code})")
|
||||
await process.wait()
|
||||
log.info(f"croc_recv: succesfully received ({code})")
|
||||
|
||||
if scope.cancel_called:
|
||||
process.terminate()
|
||||
log.info(f"croc_recv: succesfully terminated process ({code})")
|
||||
|
||||
parent._remove_pending_transfer(code)
|
@ -11,7 +11,7 @@ from gi.repository import Gdk, GLib, Gtk
|
||||
from dropship.constant import UI_DIR
|
||||
from dropship.transfer import PendingTransfer
|
||||
from dropship.ui_templates import PendingTransferRow
|
||||
from dropship.wormhole import wormhole_recv, wormhole_send
|
||||
from dropship.croc import croc_recv, croc_send
|
||||
|
||||
|
||||
class DropShip:
|
||||
@ -139,12 +139,12 @@ class DropShip:
|
||||
|
||||
async def send(self, fpath):
|
||||
self._send_spinner_on()
|
||||
code, scope = await self.nursery.start(wormhole_send, fpath, self)
|
||||
code, scope = await self.nursery.start(croc_send, fpath, self)
|
||||
self._create_pending_transfer(fpath, code, scope)
|
||||
self.clipboard.set_text(code, -1)
|
||||
self._send_spinner_off(code)
|
||||
log.info(f"send: successfully initiated transfer send ({code})")
|
||||
|
||||
async def receive(self, code):
|
||||
await self.nursery.start(wormhole_recv, code, self)
|
||||
await self.nursery.start(croc_recv, code, self)
|
||||
log.info(f"send: successfully initiated receive ({code})")
|
||||
|
Loading…
Reference in New Issue
Block a user