def _run(self, robot, options): robot_timestamp = None if options.timestamp: try: robot_timestamp = robot.time_sync.robot_timestamp_from_local_secs( time.time(), timesync_timeout_sec=1.0) except TimeSyncError as err: print("Failed to send message with timestamp: {}.".format(err)) return False msg_proto = LogAnnotationTextMessage(message=options.message, timestamp=robot_timestamp) if options.debug: msg_proto.level = LogAnnotationTextMessage.LEVEL_DEBUG elif options.warn: msg_proto.level = LogAnnotationTextMessage.LEVEL_WARN elif options.error: msg_proto.level = LogAnnotationTextMessage.LEVEL_ERROR else: msg_proto.level = LogAnnotationTextMessage.LEVEL_INFO if options.service: msg_proto.service = options.service if options.tag: msg_proto.tag = options.tag log_client = robot.ensure_client( LogAnnotationClient.default_service_name) log_client.add_text_messages([msg_proto]) return True
def test_add_text_messages(log_client): test_msg = LogAnnotationTextMessage(service='foo', level=LogAnnotationTextMessage.LEVEL_ERROR, message='hello world') log_client.add_text_messages([test_msg]) assert log_client._stub.AddLogAnnotation.call_count == 1 log_client.add_text_messages_async([test_msg]).result() assert log_client._stub.AddLogAnnotation.future.call_count == 1 assert (log_client._stub.AddLogAnnotation.call_args == log_client._stub.AddLogAnnotation.future.call_args)
def _run(self, robot, options): """Implementation of the command. Args: robot: Robot object on which to run the command. options: Parsed command-line arguments. Returns: False if TimeSyncError is caught, True otherwise. """ robot_timestamp = None if options.timestamp: try: robot_timestamp = robot.time_sync.robot_timestamp_from_local_secs( time.time(), timesync_timeout_sec=1.0) except TimeSyncError as err: print("Failed to send message with timestamp: {}.".format(err)) return False msg_proto = LogAnnotationTextMessage(message=options.message, timestamp=robot_timestamp) if options.debug: msg_proto.level = LogAnnotationTextMessage.LEVEL_DEBUG elif options.warn: msg_proto.level = LogAnnotationTextMessage.LEVEL_WARN elif options.error: msg_proto.level = LogAnnotationTextMessage.LEVEL_ERROR else: msg_proto.level = LogAnnotationTextMessage.LEVEL_INFO if options.service: msg_proto.service = options.service if options.tag: msg_proto.tag = options.tag log_client = robot.ensure_client( LogAnnotationClient.default_service_name) log_client.add_text_messages([msg_proto]) return True