How to use the aiofile.Writer function in aiofile

To help you get started, we’ve selected a few aiofile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github molior-dbs / molior / molior / tools.py View on Github external
async def write_log(build_id, line):
    """
    Writes given line to logfile for given
    build_id.

    Args:
        build_id (int): The build's id.
        line (string): The log line.

    """
    path = Path(Configuration().working_dir) / "buildout" / str(build_id) / "build.log"
    if not path.parent.exists():
        path.parent.mkdir()

    async with AIOFile(path, "a+") as afp:
        writer = Writer(afp)
        await writer(line)
github molior-dbs / molior / molior / api / upload.py View on Github external
async def ws_logs_connected(ws_client):
    token = ws_client.cirrina.request.match_info["token"]

    with Session() as session:
        build = session.query(Build).join(BuildTask).filter(BuildTask.task_id == token).first()
        if not build:
            logger.error("file_upload: no build found for token '%s'", token)
            # FIXME: disconnect
            return ws_client

    logger.debug("ws: recieving logs for build {}".format(build.id))
    filename = get_log_file_path(build.id)
    afp = AIOFile(filename, 'w')
    await afp.open()
    writer = Writer(afp)
    ws_client.cirrina.build_id = build.id
    ws_client.cirrina.buildlog = (afp, writer)
    return ws_client