Util¶
Helper functions and classes for creating client applications.
- bosdyn.client.util.cli_login_prompt(username=None, password=None)[source]¶
Interactive CLI for scripting conveniences.
- bosdyn.client.util.cli_auth(robot, username=None, password=None)[source]¶
Interactive CLI for authenticating with the robot.
- bosdyn.client.util.authenticate(robot, askpass=None)[source]¶
Generic function for authenticating with the robot.
- Tries to authenticate using the following methods, in order:
An existing auth token
Username/Password supplied in the environment
With a specified callback function, returning a username and password.
A command line prompt, if possible (stdin is a tty).
- Parameters
askpass – A function that retrieves authentication credentials if none are specified via environment variables.
- class bosdyn.client.util.DedupLoggingMessages(always_print_logger_levels={40, 50})[source]¶
Bases:
Filter
Logger filter to prevent duplicated messages from being logged.
- Parameters
always_print_logger_levels (set[logging.Level]) – A set of logging levels which any logged message at that level will always be logged.
- bosdyn.client.util.setup_logging(verbose=False, include_dedup_filter=False, always_print_logger_levels={40, 50})[source]¶
Set up a basic streaming console handler at the root logger.
- Parameters
verbose (boolean) – if False (default) show messages at INFO level and above, if True show messages at DEBUG level and above.
include_dedup_filter (boolean) – If true, the logger includes a filter which will prevent repeated duplicated messages from being logged.
always_print_logger_levels (set[logging.Level]) – A set of logging levels which any logged message at that level will always be logged.
- bosdyn.client.util.does_dedup_filter_exist(logger, always_print_logger_levels)[source]¶
Check if the DedupLoggingMessages filter exists for a logger.
- Returns
Boolean indicating if the DedupLoggingMessages filter already exists and matches the new parameters.
- bosdyn.client.util.add_base_arguments(parser)[source]¶
Add hostname argument to parser.
- Parameters
parser – Argument parser object.
- bosdyn.client.util.add_credentials_arguments(parser, credentials_no_warn=False)[source]¶
Add username/password flags to parser.
This function is marked deprecated and will be removed in a future release.
- Parameters
parser – Argument parser object.
- bosdyn.client.util.add_common_arguments(parser, credentials_no_warn=False)[source]¶
Add arguments common to most applications used for authentication.
This function is marked deprecated and will be removed in a future release. Users should use add_base_arguments instead.
- Parameters
parser – Argument parser object.
- bosdyn.client.util.read_payload_credentials(filename)[source]¶
Read the guid and secret from a file. The file should have the guid and secret as the first and second lines in the file.
- Parameters
filename – Name of the file to read.
- Returns
Tuple of (guid, secret)
- Raises
OSError if the credential file cannot be read. –
ValueError if the guid or secret are missing from the file. –
- bosdyn.client.util.get_guid_and_secret(parsed_options)[source]¶
Get the guid and secret for a payload, based on the options that were added via add_payload_credentials_arguments().
- Parameters
parsed_options – Namespace result of parser.parse_args()
- Returns
Tuple of (guid, secret)
- Raises
OSError if the credential file cannot be read. –
Exception if no applicable arguments are given. –
- bosdyn.client.util.add_payload_credentials_arguments(parser, required=True)[source]¶
Add arguments common to most payload related applications. Use get_guid_and_secret() to get the guid and secret from the resulting parse.
- Parameters
parser – Argument parser object.
required – Require either the guid/secret or file arguments to be provided.
- bosdyn.client.util.add_service_hosting_arguments(parser)[source]¶
Add arguments common to most applications hosting a GRPC service.
- Parameters
parser – Argument parser object.
- bosdyn.client.util.add_service_endpoint_arguments(parser)[source]¶
Add arguments common to most applications defining a GRPC service endpoint.
- Parameters
parser – Argument parser object.
- bosdyn.client.util.default_app_token_path()[source]¶
Do nothing, this method is kept only to maintain backwards compatibility.
Deprecated since version 2.0.1: App tokens are no longer in use. Authorization is now handled via licenses.
- class bosdyn.client.util.GrpcServiceRunner(*args, **kwargs)[source]¶
Bases:
object
A runner to start a gRPC server on a background thread and allow easy cleanup.
- Args:
- service_servicer (custom servicer class derived from ServiceServicer): Servicer that
defines server behavior.
- add_servicer_to_server_fn (function): Function generated by gRPC compilation that
attaches the servicer to the gRPC server.
- port (int): The port number the service can be accessed through on the host system.
Defaults to 0, which will assign an ephemeral port.
max_send_message_length (int): Max message length (bytes) allowed for messages sent. max_receive_message_length (int): Max message length (bytes) allowed for messages received. timeout_secs (int): Number of seconds to wait for a clean server shutdown. force_sigint_capture (bool): Re-assign the SIGINT handler to default in order to prevent
other scripts from blocking a clean exit. Defaults to True.
logger (logging.Logger): Logger to log with.
Deprecated since version 3.0.0: The GrpcServiceRunner class helper has moved to server_util.py. Please use bosdyn.client.server_util.GrpcServiceRunner.