Skip to content

Commit

Permalink
Enable --no-daemon flag for some cli tools (#514)
Browse files Browse the repository at this point in the history
Fixes #511

Signed-off-by: Dereck Wonnacott <dereck.wonnacott@havalus.com>
  • Loading branch information
dawonn-haval committed Jul 20, 2020
1 parent 95bfb05 commit acb13d9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
15 changes: 11 additions & 4 deletions ros2topic/ros2topic/verb/echo.py
Expand Up @@ -23,6 +23,7 @@
from rclpy.qos_event import SubscriptionEventCallbacks
from rclpy.qos_event import UnsupportedEventTypeError
from rclpy.utilities import get_rmw_implementation_identifier
from ros2cli.node.strategy import add_arguments as add_strategy_node_arguments
from ros2cli.node.strategy import NodeStrategy
from ros2topic.api import add_qos_arguments_to_argument_parser
from ros2topic.api import get_msg_class
Expand All @@ -42,6 +43,8 @@ class EchoVerb(VerbExtension):
"""Output messages from a topic."""

def add_arguments(self, parser, cli_name):
add_strategy_node_arguments(parser)

arg = parser.add_argument(
'topic_name',
help="Name of the ROS topic to listen to (e.g. '/chatter')")
Expand Down Expand Up @@ -88,12 +91,14 @@ def main(args):
depth=args.qos_depth, history=args.qos_history)
with NodeStrategy(args) as node:
if args.message_type is None:
message_type = get_msg_class(node, args.topic_name, include_hidden_topics=True)
message_type = get_msg_class(
node, args.topic_name, include_hidden_topics=True)
else:
message_type = get_message(args.message_type)

if message_type is None:
raise RuntimeError('Could not determine the type for the passed topic')
raise RuntimeError(
'Could not determine the type for the passed topic')

subscriber(
node, args.topic_name, message_type, callback, qos_profile, args.lost_messages)
Expand All @@ -110,7 +115,8 @@ def subscriber(
"""Initialize a node with a single subscription and spin."""
event_callbacks = None
if report_lost_messages:
event_callbacks = SubscriptionEventCallbacks(message_lost=message_lost_event_callback)
event_callbacks = SubscriptionEventCallbacks(
message_lost=message_lost_event_callback)
try:
node.create_subscription(
message_type, topic_name, callback, qos_profile, event_callbacks=event_callbacks)
Expand All @@ -136,7 +142,8 @@ def cb(msg):
def subscriber_cb_csv(truncate_length, noarr, nostr):
def cb(msg):
nonlocal truncate_length, noarr, nostr
print(message_to_csv(msg, truncate_length=truncate_length, no_arr=noarr, no_str=nostr))
print(message_to_csv(msg, truncate_length=truncate_length,
no_arr=noarr, no_str=nostr))
return cb


Expand Down
3 changes: 3 additions & 0 deletions ros2topic/ros2topic/verb/find.py
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ros2cli.node.strategy import add_arguments as add_strategy_node_arguments
from ros2cli.node.strategy import NodeStrategy

from ros2topic.api import get_topic_names_and_types
Expand All @@ -23,6 +24,8 @@ class FindVerb(VerbExtension):
"""Output a list of available topics of a given type."""

def add_arguments(self, parser, cli_name):
add_strategy_node_arguments(parser)

arg = parser.add_argument(
'topic_type',
help="Name of the ROS topic type to filter for (e.g. 'std_msg/msg/String')")
Expand Down
9 changes: 6 additions & 3 deletions ros2topic/ros2topic/verb/info.py
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ros2cli.node.strategy import add_arguments as add_strategy_node_arguments
from ros2cli.node.strategy import NodeStrategy

from ros2topic.api import get_topic_names_and_types
from ros2topic.api import TopicNameCompleter
from ros2topic.verb import VerbExtension
Expand All @@ -23,6 +23,7 @@ class InfoVerb(VerbExtension):
"""Print information about a topic."""

def add_arguments(self, parser, cli_name):
add_strategy_node_arguments(parser)
arg = parser.add_argument(
'topic_name',
help="Name of the ROS topic to get info (e.g. '/chatter')")
Expand Down Expand Up @@ -54,15 +55,17 @@ def main(self, *, args):
type_str = topic_types[0] if len(topic_types) == 1 else topic_types
print('Type: %s' % type_str, end=line_end)

print('Publisher count: %d' % node.count_publishers(topic_name), end=line_end)
print('Publisher count: %d' %
node.count_publishers(topic_name), end=line_end)
if args.verbose:
try:
for info in node.get_publishers_info_by_topic(topic_name):
print(info, end=line_end)
except NotImplementedError as e:
return str(e)

print('Subscription count: %d' % node.count_subscribers(topic_name), end=line_end)
print('Subscription count: %d' %
node.count_subscribers(topic_name), end=line_end)
if args.verbose:
try:
for info in node.get_subscriptions_info_by_topic(topic_name):
Expand Down
5 changes: 3 additions & 2 deletions ros2topic/ros2topic/verb/list.py
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ros2cli.node.strategy import add_arguments
from ros2cli.node.strategy import add_arguments as add_strategy_node_arguments
from ros2cli.node.strategy import NodeStrategy
from ros2topic.api import get_topic_names_and_types
from ros2topic.verb import VerbExtension
Expand All @@ -22,7 +22,8 @@ class ListVerb(VerbExtension):
"""Output a list of available topics."""

def add_arguments(self, parser, cli_name):
add_arguments(parser)
add_strategy_node_arguments(parser)

parser.add_argument(
'-t', '--show-types', action='store_true',
help='Additionally show the topic type')
Expand Down
3 changes: 3 additions & 0 deletions ros2topic/ros2topic/verb/type.py
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ros2cli.node.strategy import add_arguments as add_strategy_node_arguments
from ros2cli.node.strategy import NodeStrategy

from ros2topic.api import get_topic_names_and_types
Expand All @@ -23,6 +24,8 @@ class TypeVerb(VerbExtension):
"""Print a topic's type."""

def add_arguments(self, parser, cli_name):
add_strategy_node_arguments(parser)

arg = parser.add_argument(
'topic_name',
help="Name of the ROS topic to get type (e.g. '/chatter')")
Expand Down

0 comments on commit acb13d9

Please sign in to comment.