narupa.command.command_service module¶
Module providing an implementation of the CommandServicer
.
-
class
narupa.command.command_service.
CommandRegistration
¶ Bases:
tuple
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
¶ Alias for field number 1
-
info
¶ Alias for field number 0
-
-
class
narupa.command.command_service.
CommandService
¶ Bases:
narupa.protocol.command.command_service_pb2_grpc.CommandServicer
Implementation of the Command service, enabling services to register arbitrary commands which are run as callbacks.
-
GetCommands
(request, context) → narupa.protocol.command.command_service_pb2.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) → narupa.protocol.command.command_service_pb2.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.- request –
-
commands
¶ 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, Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]]], Optional[Dict[str, Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]]]], default_arguments: Optional[Dict[str, Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]]] = 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
-