Esempio n. 1
0
def _read_and_send_pty_out(proc, torrent):
    while True:
        try:
            data = gevent.os.tp_read(proc.fd, 65536)
        except OSError:
            break
        text = data.decode()
        if text.isspace():
            continue
        _add_line(torrent, text)
        if any(match in text for match in NEEDS_INPUT_SNIPPETS):
            torrent.status = Status.NEEDS_INPUT
            DB.session.commit()
            events.send_torrent(torrent)
            notifications.send_async(torrent)
Esempio n. 2
0
def _start():
    while True:
        torrent_id = QUEUE.get()
        logger.info(f"got new torrent with id {torrent_id}")
        torrent = Torrent.query.get(torrent_id)
        torrent.status = Status.PROCESSING
        DB.session.commit()
        _add_line(torrent, "[betanin] starting cli program")
        events.send_torrent(torrent)
        return_code = _import_torrent(torrent)
        _add_line(
            torrent,
            f"[betanin] program finished with exit status `{return_code}`",
        )
        torrent.status = Status.FAILED
        if return_code == 0:
            torrent.status = Status.COMPLETED
        logger.info(f"torrent finished with return code {return_code}")
        DB.session.commit()
        events.send_torrent(torrent)
        notifications.send_async(torrent)