Skip to content

Creating & Retrieving Projects

Creating new projects

New projects for new data can be created in the following way:

Source: examples/gRPC/meta/gRPC_pb_createProject.py

#!/usr/bin/env python3
# NOTE: This file is referenced in the following mkdocs files:
#   projects.md
# Any changes done in here will be reflected in there
from typing import Tuple

from grpc import Channel
from seerep.pb import meta_operations_pb2_grpc as metaOperations
from seerep.pb import projectCreation_pb2
from seerep.util.common import get_gRPC_channel


def create_project(
    grpc_channel: Channel = get_gRPC_channel(),
) -> Tuple[str, str]:
    stub = metaOperations.MetaOperationsStub(grpc_channel)
    response = stub.CreateProject(
        projectCreation_pb2.ProjectCreation(
            name="testproject", mapFrameId="map"
        )
    )

    return response.name, response.uuid


if __name__ == "__main__":
    ret = create_project()
    print("The new project on the server is (name/uuid):")
    print("\t" + ret[0] + " " + ret[1])

Output:

The new project on the server is (name/uuid):
        testproject ff739be8-cf0c-4657-bff0-f66f3e7f578d

Retrieving projects

After we created two projects, we can query them. Currently the name doesn't have to be unique.

Source: examples/gRPC/meta/gRPC_fb_getProjects.py

#!/usr/bin/env python3
# NOTE: This file is referenced in the following mkdocs files:
#   projects.md
# Any changes done in here will be reflected in there
from typing import List

import flatbuffers
from grpc import Channel
from seerep.fb import Empty, ProjectInfo, ProjectInfos
from seerep.fb import meta_operations_grpc_fb as metaOperations
from seerep.util.common import get_gRPC_channel


def get_projects_raw(
    grpc_channel: Channel = get_gRPC_channel(),
) -> bytearray:
    """
    Returns: bytearray of type ProjectInfos
    """
    stub = metaOperations.MetaOperationsStub(grpc_channel)

    builder = flatbuffers.Builder(1024)
    Empty.Start(builder)
    emptyMsg = Empty.End(builder)
    builder.Finish(emptyMsg)
    buf = builder.Output()

    responseBuf = stub.GetProjects(bytes(buf))
    return responseBuf


def get_projects(
    grpc_channel: Channel = get_gRPC_channel(),
) -> ProjectInfos.ProjectInfos:
    return ProjectInfos.ProjectInfos.GetRootAs(get_projects_raw(grpc_channel))


if __name__ == "__main__":
    response = get_projects()

    projects_list: List[ProjectInfo.ProjectInfo] = []

    for i in range(response.ProjectsLength()):
        projects_list.append(response.Projects(i))

    print("The server has the following projects (name/uuid):")
    for project in projects_list:
        print(
            "\t"
            + project.Name().decode("utf-8")
            + " "
            + project.Uuid().decode("utf-8")
        )

Output:

The server has the following projects (name/uuid):
    testproject 842de425-2d50-4adf-8aa3-6df257a7c76c
    testproject ff739be8-cf0c-4657-bff0-f66f3e7f578d

Source: examples/gRPC/meta/gRPC_pb_getProjects.py

#!/usr/bin/env python3
# NOTE: This file is referenced in the following mkdocs files:
#   projects.md
# Any changes done in here will be reflected in there
from typing import List, Tuple

from google.protobuf import empty_pb2
from grpc import Channel
from seerep.pb import meta_operations_pb2_grpc as metaOperations
from seerep.util.common import get_gRPC_channel


def get_projects(
    grpc_channel: Channel = get_gRPC_channel(),
) -> List[Tuple[str, str]]:
    stub = metaOperations.MetaOperationsStub(grpc_channel)

    response = stub.GetProjects(empty_pb2.Empty())

    projects_list: List[Tuple[str, str]] = []
    print("The server has the following projects (name/uuid):")

    for projectinfo in response.projects:
        projects_list.append((projectinfo.name, projectinfo.uuid))

    return projects_list


if __name__ == "__main__":
    project_list = get_projects()
    for proj in project_list:
        print("\t" + proj[0] + " " + proj[1])

Output:

The server has the following projects (name/uuid):
    testproject 842de425-2d50-4adf-8aa3-6df257a7c76c
    testproject ff739be8-cf0c-4657-bff0-f66f3e7f578d