Browse Source

Wire up code gathering

unifiedWindowUI
Luke Murphy 4 years ago
parent
commit
2e724fcf66
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 22
      dropship.py

22
dropship.py

@ -101,14 +101,30 @@ class DropShip:
"""Schedule a task on the event loop.""" """Schedule a task on the event loop."""
loop.call_soon_threadsafe(asyncio.ensure_future, function) loop.call_soon_threadsafe(asyncio.ensure_future, function)
async def read_lines(self, stream, pattern):
"""Read stdout from a command and match lines."""
# TODO(decentral1se): if pattern doesnt match, trapped forever
while True:
line = await stream.readline()
decoded = line.decode("utf-8").strip()
if pattern in decoded:
return decoded
async def wormhole_send(self, widget, fpath): async def wormhole_send(self, widget, fpath):
"""Run `wormhole send` on a local file path.""" """Run `wormhole send` on a local file path."""
process = await asyncio.create_subprocess_exec( process = await asyncio.create_subprocess_exec(
"wormhole", "send", fpath, stdout=subprocess.PIPE "wormhole",
"send",
fpath,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
) )
line = await self.read_lines(process.stderr, "wormhole receive")
code = line.split()[-1]
log.info(f"Wormhole send produced f{code}")
async for line in process.stdout: # TODO(decentral1se): waits forever...
log.info(line) await process.wait()
async def main(): async def main():

Loading…
Cancel
Save