nanover.command.command_service module
Module providing an implementation of the CommandServicer
.
- class nanover.command.command_service.CommandRegistration(info: CommandInfo, callback: Callable[[...], Dict[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]]] | None] | Callable[[], Dict[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]]] | None])
Bases:
NamedTuple
Represents a registration of a command on the service, consisting of a
CommandInfo
detailing the command name and default arguments, and an associated callback.- callback: Callable[[...], Dict[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]]] | None] | Callable[[], Dict[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]]] | None]
Alias for field number 1
- info: CommandInfo
Alias for field number 0
- class nanover.command.command_service.CommandService
Bases:
CommandServicer
Implementation of the Command service, enabling services to register arbitrary commands which are run as callbacks.
- GetCommands(request, context) GetCommandsReply
GRPC method to get all of the commands available on this service. :param request:
GetCommandsRequest
:param context: GRPC context. :return:GetCommandsReply
, detailing all the available commands.
- RunCommand(request, context) CommandReply
GRPC method to run a command.
- Parameters:
request –
CommandMessage
detailing the command to run and any arguments.context – GRPC context.
- Returns:
CommandReply
, consisting of any results of the command.
- property commands: Dict[str, CommandRegistration]
Gets a copy of the commands that have been registered, as
CommandRegistration
, including their names, default arguments and registered callback.- Returns:
A copy of the dictionary of commands that have been registered.
- register_command(name: str, callback: Callable[[...], Dict[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]]] | None] | Callable[[], Dict[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]]] | None], default_arguments: Dict[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]]] | None = None)
Registers a command with this service
- Parameters:
name – Name of the command to register
callback – Method to be called whenever the given command name is run by a client.
default_arguments – A dictionary of the arguments of the callback and their default values.
- Raises:
ValueError – Raised when a command with the same name already exists.
- unregister_command(name)
Deletes a command from this service.
- Parameters:
name – Name of the command to delete