Exemplo n.º 1
0
def main() -> None:

    parser = argparse.ArgumentParser(description=SERVICE_NAME)
    parser.add_argument("-s", "--swagger", action="store_true", default=False)
    parser.add_argument("-m",
                        "--mock",
                        action="store_true",
                        default=env.get_bool("ARCOR2_DOBOT_MOCK"))

    parser.add_argument(
        "-d",
        "--debug",
        help="Set logging level to debug.",
        action="store_const",
        const=logging.DEBUG,
        default=logging.DEBUG
        if env.get_bool("ARCOR2_DOBOT_DEBUG") else logging.INFO,
    )

    args = parser.parse_args()
    logger.setLevel(args.debug)

    global _mock
    _mock = args.mock
    if _mock:
        logger.info("Starting as a mock!")

    if not args.swagger:
        scene_service.wait_for()

    run_app(app, SERVICE_NAME, version(), port_from_url(URL), [Pose, Joint],
            args.swagger)

    if _dobot:
        _dobot.cleanup()
Exemplo n.º 2
0
def start_processes() -> Iterator[None]:

    my_env = os.environ.copy()

    scene_port = find_free_port()
    scene_url = f"http://0.0.0.0:{scene_port}"

    my_env["ARCOR2_SCENE_SERVICE_URL"] = scene_url
    my_env["ARCOR2_SCENE_SERVICE_MOCK_PORT"] = str(scene_port)
    scene_service.URL = scene_url

    processes = []

    for cmd in ("./src.python.arcor2_mocks.scripts/mock_scene.pex",):
        processes.append(subprocess.Popen(cmd, env=my_env, stdout=subprocess.PIPE))

    scene_service.wait_for(20)

    yield None

    finish_processes(processes)
Exemplo n.º 3
0
def start_processes() -> Iterator[None]:

    global _arserver_port

    _arserver_port = find_free_port()

    with tempfile.TemporaryDirectory() as tmp_dir:

        my_env = os.environ.copy()

        project_port = find_free_port()
        project_url = f"http://0.0.0.0:{project_port}"
        my_env["ARCOR2_PROJECT_SERVICE_URL"] = project_url
        my_env["ARCOR2_PROJECT_SERVICE_MOCK_PORT"] = str(project_port)
        project_service.URL = project_url

        scene_port = find_free_port()
        scene_url = f"http://0.0.0.0:{scene_port}"
        my_env["ARCOR2_SCENE_SERVICE_URL"] = scene_url
        my_env["ARCOR2_SCENE_SERVICE_MOCK_PORT"] = str(scene_port)
        scene_service.URL = scene_url

        my_env["ARCOR2_EXECUTION_URL"] = f"ws://0.0.0.0:{find_free_port()}"
        my_env["ARCOR2_PROJECT_PATH"] = os.path.join(tmp_dir, "packages")

        my_env["ARCOR2_SERVER_PORT"] = str(_arserver_port)
        my_env["ARCOR2_DATA_PATH"] = os.path.join(tmp_dir, "data")

        processes = []

        for cmd in (
                "./src.python.arcor2_mocks.scripts/mock_project.pex",
                "./src.python.arcor2_mocks.scripts/mock_scene.pex",
                "./src.python.arcor2_execution.scripts/execution.pex",
        ):
            processes.append(
                sp.Popen(cmd, env=my_env, stdout=sp.PIPE, stderr=sp.STDOUT))

        scene_service.wait_for(60)

        # it may take some time for project service to come up so give it some time
        for _ in range(3):
            upload_proc = sp.Popen(
                "./src.python.arcor2_yumi.scripts/upload_objects.pex",
                env=my_env,
                stdout=sp.PIPE,
                stderr=sp.STDOUT)
            ret = upload_proc.communicate()
            if upload_proc.returncode == 0:
                log_proc_output(ret)
                break
        else:
            raise Exception("Failed to upload objects.")

        LOGGER.info(f"Starting ARServer listening on port  {_arserver_port}.")

        arserver_proc = sp.Popen(
            "./src.python.arcor2_arserver.scripts/arserver.pex",
            env=my_env,
            stdout=sp.PIPE,
            stderr=sp.STDOUT)

        processes.append(arserver_proc)
        assert arserver_proc.stdout is not None

        while True:
            line = arserver_proc.stdout.readline().decode().strip()
            if not line or "Server initialized." in line:  # TODO this is not ideal
                break

        if arserver_proc.poll():
            finish_processes(processes)
            raise Exception("ARServer died.")

        yield None

        finish_processes(processes)