示例#1
0
def main_router(loop, virtual_smoothie_env, hardware):
    from opentrons.api.routers import MainRouter
    router = MainRouter(hardware, loop)
    router.wait_until = partial(wait_until,
                                notifications=router.notifications,
                                loop=loop)
    yield router
示例#2
0
def main_router(loop, virtual_smoothie_env, hardware):
    router = MainRouter(hardware, loop)
    router.wait_until = partial(
        wait_until,
        notifications=router.notifications,
        loop=loop)
    yield router
示例#3
0
def init(hardware: 'HardwareAPILike' = None,
         loop: asyncio.AbstractEventLoop = None):
    """
    Builds an application and sets up RPC and HTTP servers with it.

    :param loop: A specific aiohttp event loop to use. If not specified, the
                 server will use the default event loop.
    :param hardware: The hardware manager or hardware adapter to connect to.
                     If not specified, the server will use
                     :py:attr:`opentrons.hardware`
    """

    app = web.Application(middlewares=[error_middleware])
    app['com.opentrons.hardware'] = hardware
    app['com.opentrons.motion_lock'] = ThreadedAsyncLock()
    app['com.opentrons.rpc'] = RPCServer(
        app, MainRouter(hardware, lock=app['com.opentrons.motion_lock']))
    app['com.opentrons.response_file_tempdir'] = tempfile.mkdtemp()
    app['com.opentrons.http'] = HTTPServer(app, CONFIG['log_dir'])

    async def dispose_response_file_tempdir(app):
        temppath = app.get('com.opentrons.response_file_tempdir')
        if temppath:
            try:
                shutil.rmtree(temppath)
            except Exception:
                log.exception(f"failed to remove app temp path {temppath}")

    app.on_shutdown.append(dispose_response_file_tempdir)
    app.on_shutdown.freeze()
    return app
示例#4
0
def init(hardware: 'HardwareAPILike' = None):
    """
    Builds an application and sets up RPC and HTTP servers with it.

    :param loop: A specific aiohttp event loop to use. If not specified, the
                 server will use the default event loop.
    :param hardware: The hardware manager or hardware adapter to connect to.
                     If not specified, the server will use
                     :py:attr:`opentrons.hardware`
    """

    app = web.Application(middlewares=[error_middleware])
    if hardware:
        checked_hardware = hardware
    else:
        checked_hardware = opentrons.hardware
    app['com.opentrons.hardware'] = checked_hardware
    app['com.opentrons.motion_lock'] = ThreadedAsyncLock()
    app['com.opentrons.rpc'] = RPCServer(
        app, MainRouter(checked_hardware,
                        lock=app['com.opentrons.motion_lock']))
    app['com.opentrons.http'] = HTTPServer(app, CONFIG['log_dir'])
    app.on_shutdown.freeze()
    return app