Exemplo n.º 1
0
def main():
    arg_parser = build_arg_parser()
    # System 3.0 server startup is:
    # python -m opentrons.server.main -U $OT_SERVER_UNIX_SOCKET_PATH
    # opentrons.server.main:init
    # In which case, we add a mock argument specifically to indicate that
    # this is a system 3.0 init path. This argument otherwise has no meaning
    arg_parser.add_argument(
        'patch_old_init',
        metavar='OLD_STYLE_INIT',
        nargs='?',
        default=None,
        help="The old-style way to initialize the server with a function name."
             " Use to force the system to start with opentrons.main "
             "instead of server.main"
    )
    args = arg_parser.parse_args()

    # If running system 3.0, then redirect to new 3.4 entrypoint
    # in opentrons.main
    if args.patch_old_init is not None:
        import opentrons.main
        opentrons.main.run(**vars(args))
    else:
        server.run(args.hostname, args.port, args.path)
        arg_parser.exit(message="Stopped\n")
Exemplo n.º 2
0
def run(**kwargs):  # noqa(C901)
    """
    This function was necessary to separate from main() to accommodate for
    server startup path on system 3.0, which is server.main. In the case where
    the api is on system 3.0, server.main will redirect to this function with
    an additional argument of 'patch_old_init'. kwargs are hence used to allow
    the use of different length args
    """
    hardware = initialize(bool(kwargs.get('hardware_server', False)),
                          kwargs.get('hardware_server_socket'))

    server.run(hardware, kwargs.get('hostname'), kwargs.get('port'),
               kwargs.get('path'))
Exemplo n.º 3
0
def run(hardware, **kwargs):  # noqa(C901)
    """
    This function was necessary to separate from main() to accommodate for
    server startup path on system 3.0, which is server.main. In the case where
    the api is on system 3.0, server.main will redirect to this function with
    an additional argument of 'patch_old_init'. kwargs are hence used to allow
    the use of different length args
    """
    loop = asyncio.get_event_loop()

    if ff.use_protocol_api_v2():
        robot_conf = loop.run_until_complete(hardware.get_config())
    else:
        robot_conf = hardware.config

    logging_config.log_init(robot_conf.log_level)

    log.info("API server version:  {}".format(__version__))
    if not os.environ.get("ENABLE_VIRTUAL_SMOOTHIE"):
        initialize_robot(loop, hardware)
        if ff.use_protocol_api_v2():
            loop.run_until_complete(hardware.cache_instruments())
        if not ff.disable_home_on_boot():
            log.info("Homing Z axes")
            if ff.use_protocol_api_v2():
                loop.run_until_complete(hardware.home_z())
            else:
                hardware.home_z()
        try:
            udev.setup_rules_file()
        except Exception:
            log.exception(
                "Could not setup udev rules, modules may not be detected")

    if kwargs.get('hardware_server'):
        if ff.use_protocol_api_v2():
            loop.run_until_complete(
                install_hardware_server(kwargs['hardware_server_socket'],
                                        hardware._api))
        else:
            log.warning(
                "Hardware server requested but apiv1 selected, not starting")
    server.run(
        hardware,
        kwargs.get('hostname'),
        kwargs.get('port'),
        kwargs.get('path'),
        loop)