forked from ros2/rclcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial command line interface (ros2#12)
* initial cli interface * get available topics * remove rclpy dependency * add disclaimer * remove yaml dependency
- Loading branch information
1 parent
ee8b5dd
commit 7ab5efc
Showing
12 changed files
with
237 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*__pycache__* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2018 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from ros2cli.command import add_subparsers | ||
from ros2cli.command import CommandExtension | ||
from ros2cli.verb import get_verb_extensions | ||
|
||
|
||
class BagCommand(CommandExtension): | ||
"""Various rosbag related sub-commands.""" | ||
|
||
def add_arguments(self, parser, cli_name): | ||
self._subparser = parser | ||
|
||
# get verb extensions and let them add their arguments | ||
verb_extensions = get_verb_extensions('ros2bag.verb') | ||
add_subparsers( | ||
parser, cli_name, '_verb', verb_extensions, required=False) | ||
|
||
def main(self, *, parser, args): | ||
if not hasattr(args, '_verb'): | ||
# in case no verb was passed | ||
self._subparser.print_help() | ||
return 0 | ||
|
||
extension = getattr(args, '_verb') | ||
|
||
print('DISCLAIMER') | ||
print('ros2 bag is currently under development and not ready to use yet') | ||
# call the verb's main method | ||
return extension.main(args=args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2018 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from ros2cli.plugin_system import PLUGIN_SYSTEM_VERSION | ||
from ros2cli.plugin_system import satisfies_version | ||
|
||
|
||
class VerbExtension: | ||
""" | ||
The extension point for 'bag' verb extensions. | ||
The following properties must be defined: | ||
* `NAME` (will be set to the entry point name) | ||
The following methods must be defined: | ||
* `main` | ||
The following methods can be defined: | ||
* `add_arguments` | ||
""" | ||
|
||
NAME = None | ||
EXTENSION_POINT_VERSION = '0.1' | ||
|
||
def __init__(self): | ||
super(VerbExtension, self).__init__() | ||
satisfies_version(PLUGIN_SYSTEM_VERSION, '^0.1') | ||
|
||
def add_arguments(self, parser, cli_name): | ||
pass | ||
|
||
def main(self, *, args): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2018 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
|
||
from ros2bag.verb import VerbExtension | ||
|
||
|
||
class InfoVerb(VerbExtension): | ||
"""ros2 bag info.""" | ||
|
||
def add_arguments(self, parser, cli_name): # noqa: D102 | ||
arg = parser.add_argument( | ||
'bag_file', help='bag file to introspect') | ||
|
||
def main(self, *, args): # noqa: D102 | ||
bag_file = args.bag_file | ||
print('calling ros2 bag info on', bag_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2018 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from ros2bag.verb import VerbExtension | ||
|
||
|
||
class PlayVerb(VerbExtension): | ||
"""ros2 bag play.""" | ||
|
||
def add_arguments(self, parser, cli_name): # noqa: D102 | ||
parser.add_argument( | ||
'bag_file', help='bag file to replay') | ||
|
||
def main(self, *, args): # noqa: D102 | ||
bag_file = args.bag_file | ||
print('calling ros2 bag play on', bag_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2018 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
import time | ||
|
||
from ros2cli.node.strategy import add_arguments | ||
from ros2cli.node.strategy import NodeStrategy | ||
|
||
from ros2bag.verb import VerbExtension | ||
|
||
|
||
class RecordVerb(VerbExtension): | ||
"""ros2 bag record.""" | ||
|
||
def add_arguments(self, parser, cli_name): # noqa: D102 | ||
add_arguments(parser) | ||
parser.add_argument( | ||
'-a', '--all', action='store_true', help='recording all topics') | ||
parser.add_argument( | ||
'topics', nargs='*', help='topics to be recorded') | ||
|
||
def main(self, *, args): # noqa: D102 | ||
if args.all and args.topics: | ||
print('invalid choice: Can not specify topics and -a at the same time') | ||
return | ||
|
||
with NodeStrategy(args) as node: | ||
if args.all: | ||
t_and_n = node.get_topic_names_and_types() | ||
print(t_and_n) | ||
topics = [t for t,n in node.get_topic_names_and_types()] | ||
if args.topics: | ||
topics = args.topics | ||
print('topics to be recorded:', topics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from setuptools import find_packages | ||
from setuptools import setup | ||
|
||
setup( | ||
name='ros2bag', | ||
version='0.0.0', | ||
packages=find_packages(exclude=['test']), | ||
install_requires=['ros2cli'], | ||
zip_safe=True, | ||
author='Karsten Knese', | ||
author_email='karsten@osrfoundation.org', | ||
maintainer='Karsten Knese', | ||
maintainer_email='karsten@osrfoundation.org', | ||
keywords=[], | ||
classifiers=[ | ||
'Environment :: Console', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: Apache Software License', | ||
'Programming Language :: Python', | ||
], | ||
description='Entry point for rosbag in ROS 2', | ||
long_description="""\ | ||
The package provides the rosbag command for the ROS 2 command line tools.""", | ||
license='Apache License, Version 2.0', | ||
tests_require=['pytest'], | ||
entry_points={ | ||
'ros2cli.command': [ | ||
'bag = ros2bag.command.bag:BagCommand', | ||
], | ||
'ros2cli.extension_point': [ | ||
'ros2bag.verb = ros2bag.verb:VerbExtension', | ||
], | ||
'ros2bag.verb': [ | ||
'info = ros2bag.verb.info:InfoVerb', | ||
'play = ros2bag.verb.play:PlayVerb', | ||
'record = ros2bag.verb.record:RecordVerb', | ||
], | ||
} | ||
) |