Skip to content

Commit

Permalink
Use format strings for topic endpoint info printing
Browse files Browse the repository at this point in the history
Signed-off-by: Emerson Knapp <[email protected]>
  • Loading branch information
Emerson Knapp committed Apr 1, 2021
1 parent 24ae7d2 commit a491ba1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rclpy/rclpy/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def from_msg(cls, msg):

@classmethod
def Infinite(cls):
return cls(nanoseconds=_rclpy.rclpy_RMW_DURATION_INFINITE)
return cls(nanoseconds=_rclpy.RMW_DURATION_INFINITE)

def get_c_duration(self):
return self._duration_handle
29 changes: 15 additions & 14 deletions rclpy/rclpy/topic_endpoint_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,18 @@ def __eq__(self, other):
for slot in self.__slots__)

def __str__(self):
result = 'Node name: %s\n' % self.node_name
result += 'Node namespace: %s\n' % self.node_namespace
result += 'Topic type: %s\n' % self.topic_type
result += 'Endpoint type: %s\n' % self.endpoint_type.name
result += 'GID: %s\n' % '.'.join(format(x, '02x') for x in self.endpoint_gid)
result += 'QoS profile:\n'
result += ' Reliability: %s\n' % self.qos_profile.reliability.name
result += ' Durability: %s\n' % self.qos_profile.durability.name
result += ' Lifespan: %s\n' % str(self.qos_profile.lifespan)
result += ' Deadline: %s\n' % str(self.qos_profile.deadline)
result += ' Liveliness: %s\n' % self.qos_profile.liveliness.name
result += ' Liveliness lease duration: %s' % \
str(self.qos_profile.liveliness_lease_duration)
return result
gid = '.'.join(format(x, '02x') for x in self.endpoint_gid)
return '\n'.join([
f'Node name: {self.node_name}',
f'Node namespace: {self.node_namespace}',
f'Topic type: {self.topic_type}',
f'Endpoint type: {self.endpoint_type.name}',
f'GID: {gid}',
'QoS profile:',
f' Reliability: {self.qos_profile.reliability.name}',
f' Durability: {self.qos_profile.durability.name}',
f' Lifespan: {self.qos_profile.lifespan}',
f' Deadline: {self.qos_profile.deadline}',
f' Liveliness: {self.qos_profile.liveliness.name}',
f' Liveliness lease duration: {self.qos_profile.liveliness_lease_duration}',
])
1 change: 0 additions & 1 deletion rclpy/src/rclpy/_rclpy_pybind11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ PYBIND11_MODULE(_rclpy_pybind11, m) {
.def_readonly("compatibility", &rclpy::QoSCheckCompatibleResult::compatibility)
.def_readonly("reason", &rclpy::QoSCheckCompatibleResult::reason);


py::register_exception<rclpy::RCUtilsError>(m, "RCUtilsError", PyExc_RuntimeError);
py::register_exception<rclpy::RMWError>(m, "RMWError", PyExc_RuntimeError);
auto rclerror = py::register_exception<rclpy::RCLError>(m, "RCLError", PyExc_RuntimeError);
Expand Down

0 comments on commit a491ba1

Please sign in to comment.