Beispiel #1
0
async def set_log_level(request: web.Request) -> web.Response:
    """
    Set the log level of the API logs (serial logs are unaffected)

    POST /settings/log_level {"log_level": str level} -> 200 OK

    The level has to be in ("debug", "info", "warning", "error")
    """

    try:
        body = await request.json()
    except JSONDecodeError:
        return web.json_response(status=400,
                                 data={"message": "Request must be json"})
    if 'log_level' not in body:
        return web.json_response(
            status=400, data={"message": "body must have log_level key"})

    log_level = body['log_level'].upper()
    level_val = getattr(logging, log_level, None)
    if level_val is None:
        return web.json_response(
            status=400, data={"message": f"invalid log_level {log_level}"})

    logging.getLogger('opentrons').setLevel(level_val)
    hw = request.app['com.opentrons.hardware']

    await hw.update_config(log_level=log_level)
    rc.save_robot_settings(hw.config)
    return web.json_response(status=200,
                             data={'message': f'log_level set to {log_level}'})
Beispiel #2
0
async def reset(request: web.Request) -> web.Response:  # noqa(C901)
    """ Execute a reset of the requested parts of the user configuration.
    """
    data = await request.json()
    ok, bad_key = _check_reset(data)
    if not ok:
        return web.json_response(
            {'message': '{} is not a valid reset option'.format(bad_key)},
            status=400)
    log.info("Reset requested for {}".format(', '.join(data.keys())))
    if data.get('tipProbe'):
        config = rc.load()
        if ff.use_protocol_api_v2():
            config = config._replace(
                instrument_offset=rc.build_fallback_instrument_offset({}))
        else:
            config.tip_length.clear()
        rc.save_robot_settings(config)
    if data.get('labwareCalibration'):
        labware.clear_calibrations()
        if not ff.use_protocol_api_v2():
            db.reset()

    if data.get('customLabware'):
        labware.delete_all_custom_labware()

    if data.get('bootScripts'):
        if IS_ROBOT:
            if os.path.exists('/data/boot.d'):
                shutil.rmtree('/data/boot.d')
        else:
            log.debug('Not on pi, not removing /data/boot.d')
    return web.json_response({}, status=200)
Beispiel #3
0
def save_config(config) -> str:
    try:
        robot_configs.save_robot_settings(config)
        robot_configs.save_deck_calibration(config)
        result = robot_configs.load()
    except Exception as e:
        result = repr(e)
    return result
Beispiel #4
0
def reset_tip_probe():
    config = rc.load()
    config = config._replace(
        instrument_offset=rc.build_fallback_instrument_offset({}))
    if ff.enable_calibration_overhaul():
        delete.clear_tip_length_calibration()
    else:
        config.tip_length.clear()
    rc.save_robot_settings(config)
Beispiel #5
0
async def post_log_level_local(
    log_level: LogLevel, hardware: HardwareAPILike = Depends(get_hardware)
) -> V1BasicResponse:
    """Update local log level"""
    level = log_level.log_level
    if not level:
        raise V1HandlerError(message="log_level must be set",
                             status_code=status.HTTP_422_UNPROCESSABLE_ENTITY)
    # Level name is upper case
    level_name = level.value.upper()
    # Set the log levels
    for logger_name in ('opentrons', 'robot_server', 'uvicorn'):
        logging.getLogger(logger_name).setLevel(level.level_id)
    # Update and save settings
    await hardware.update_config(log_level=level_name)  # type: ignore
    robot_configs.save_robot_settings(hardware.config)  # type: ignore

    return V1BasicResponse(message=f'log_level set to {level}')
Beispiel #6
0
async def reset(request: web.Request) -> web.Response:  # noqa(C901)
    """ Execute a reset of the requested parts of the user configuration.

    POST /settings/reset {resetOption: Any}

    -> 200 OK, {"links": {"restart": uri}}
    -> 400 Bad Request, {"error": error-shortmessage, "message": str}
    """
    data = await request.json()
    ok, bad_key = _check_reset(data)
    if not ok:
        return web.json_response(
            {
                'error': 'bad-reset-option',
                'message': f'{bad_key} is not a valid reset option'
            },
            status=400)
    log.info("Reset requested for {}".format(', '.join(data.keys())))
    if data.get('tipProbe'):
        config = rc.load()
        config = config._replace(
            instrument_offset=rc.build_fallback_instrument_offset({}))
        config.tip_length.clear()
        rc.save_robot_settings(config)

    if data.get('labwareCalibration'):
        labware.clear_calibrations()
        db.reset()

    if data.get('customLabware'):
        labware.delete_all_custom_labware()

    if data.get('bootScripts'):
        if IS_ROBOT:
            if os.path.exists('/data/boot.d'):
                shutil.rmtree('/data/boot.d')
        else:
            log.debug('Not on pi, not removing /data/boot.d')
    return web.json_response({}, status=200)
Beispiel #7
0
def update_instrument_config(instrument,
                             measured_center) -> Tuple[Point, float]:
    """
    Update config and pose tree with instrument's x and y offsets
    and tip length based on delta between probe center and measured_center,
    persist updated config and return it
    """
    from copy import deepcopy
    from opentrons.trackers.pose_tracker import update

    robot = instrument.robot
    config = robot.config
    instrument_offset = deepcopy(config.instrument_offset)

    dx, dy, dz = array(measured_center) - config.tip_probe.center

    log.debug("This is measured probe center dx {}".format(Point(dx, dy, dz)))
    # any Z offset will adjust the tip length, so instruments have Z=0 offset
    old_x, old_y, _ = instrument_offset[instrument.mount][instrument.type]
    instrument_offset[instrument.mount][instrument.type] = \
        (old_x - dx, old_y - dy, 0.0)
    tip_length = deepcopy(config.tip_length)
    tip_length[instrument.model] = tip_length[instrument.model] + dz

    config = config \
        ._replace(instrument_offset=instrument_offset) \
        ._replace(tip_length=tip_length)
    robot.config = config
    log.debug("Updating config for {} instrument".format(instrument.mount))
    robot_configs.save_robot_settings(config)

    new_coordinates = change_base(
        robot.poses, src=instrument, dst=instrument.instrument_mover) - Point(
            dx, dy, 0.0)
    robot.poses = update(robot.poses, instrument, new_coordinates)

    return robot.config
Beispiel #8
0
def reset_tip_probe():
    config = rc.load()
    config = config._replace(
        instrument_offset=rc.build_fallback_instrument_offset({}))
    config.tip_length.clear()
    rc.save_robot_settings(config)