From e8c63380fbc04c77975e59db00f983af8cfbf411 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Fri, 6 Jul 2018 14:48:46 -0700 Subject: [PATCH 1/5] initial cli interface --- ros2bag/.gitignore | 1 + ros2bag/CMakeLists.txt | 33 ---------------------- ros2bag/package.xml | 19 ++++++++----- ros2bag/ros2bag/__init__.py | 0 ros2bag/ros2bag/api/__init__.py | 17 +++++++++++ ros2bag/ros2bag/command/__init__.py | 0 ros2bag/ros2bag/command/bag.py | 40 ++++++++++++++++++++++++++ ros2bag/ros2bag/verb/__init__.py | 44 +++++++++++++++++++++++++++++ ros2bag/ros2bag/verb/info.py | 29 +++++++++++++++++++ ros2bag/ros2bag/verb/play.py | 27 ++++++++++++++++++ ros2bag/ros2bag/verb/record.py | 35 +++++++++++++++++++++++ ros2bag/setup.py | 39 +++++++++++++++++++++++++ 12 files changed, 244 insertions(+), 40 deletions(-) create mode 100644 ros2bag/.gitignore delete mode 100644 ros2bag/CMakeLists.txt create mode 100644 ros2bag/ros2bag/__init__.py create mode 100644 ros2bag/ros2bag/api/__init__.py create mode 100644 ros2bag/ros2bag/command/__init__.py create mode 100644 ros2bag/ros2bag/command/bag.py create mode 100644 ros2bag/ros2bag/verb/__init__.py create mode 100644 ros2bag/ros2bag/verb/info.py create mode 100644 ros2bag/ros2bag/verb/play.py create mode 100644 ros2bag/ros2bag/verb/record.py create mode 100644 ros2bag/setup.py diff --git a/ros2bag/.gitignore b/ros2bag/.gitignore new file mode 100644 index 000000000..cd4c22c48 --- /dev/null +++ b/ros2bag/.gitignore @@ -0,0 +1 @@ +*__pycache__* diff --git a/ros2bag/CMakeLists.txt b/ros2bag/CMakeLists.txt deleted file mode 100644 index 83b7e6bda..000000000 --- a/ros2bag/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -cmake_minimum_required(VERSION 3.5) -project(ros2bag) - -# Default to C99 -if(NOT CMAKE_C_STANDARD) - set(CMAKE_C_STANDARD 99) -endif() - -# Default to C++14 -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) -endif() - -if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wall -Wextra -Wpedantic) -endif() - -# find dependencies -find_package(ament_cmake REQUIRED) -find_package(ros2cli REQUIRED) - -if(BUILD_TESTING) - find_package(ament_lint_auto REQUIRED) - # the following line skips the linter which checks for copyrights - # remove the line when a copyright and license is present in all source files - set(ament_cmake_copyright_FOUND TRUE) - # the following line skips cpplint (only works in a git repo) - # remove the line when this package is a git repo - set(ament_cmake_cpplint_FOUND TRUE) - ament_lint_auto_find_test_dependencies() -endif() - -ament_package() diff --git a/ros2bag/package.xml b/ros2bag/package.xml index aac48d566..4d70ccb64 100644 --- a/ros2bag/package.xml +++ b/ros2bag/package.xml @@ -3,18 +3,23 @@ ros2bag 0.0.0 - ROSBag2 verb for ros2cli - Karsten Knese + + Entry point for rosbag in ROS 2 + + Karsten Knese Apache License 2.0 - ament_cmake - + rclpy ros2cli - ament_lint_auto - ament_lint_common + python3-yaml + + ament_copyright + ament_flake8 + ament_pep257 + python3-pytest - ament_cmake + ament_python diff --git a/ros2bag/ros2bag/__init__.py b/ros2bag/ros2bag/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ros2bag/ros2bag/api/__init__.py b/ros2bag/ros2bag/api/__init__.py new file mode 100644 index 000000000..dab5079fa --- /dev/null +++ b/ros2bag/ros2bag/api/__init__.py @@ -0,0 +1,17 @@ +# 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 rclpy + + diff --git a/ros2bag/ros2bag/command/__init__.py b/ros2bag/ros2bag/command/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ros2bag/ros2bag/command/bag.py b/ros2bag/ros2bag/command/bag.py new file mode 100644 index 000000000..d64f0016b --- /dev/null +++ b/ros2bag/ros2bag/command/bag.py @@ -0,0 +1,40 @@ +# 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') + + # call the verb's main method + return extension.main(args=args) diff --git a/ros2bag/ros2bag/verb/__init__.py b/ros2bag/ros2bag/verb/__init__.py new file mode 100644 index 000000000..d8ae09591 --- /dev/null +++ b/ros2bag/ros2bag/verb/__init__.py @@ -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() diff --git a/ros2bag/ros2bag/verb/info.py b/ros2bag/ros2bag/verb/info.py new file mode 100644 index 000000000..9926414c5 --- /dev/null +++ b/ros2bag/ros2bag/verb/info.py @@ -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) diff --git a/ros2bag/ros2bag/verb/play.py b/ros2bag/ros2bag/verb/play.py new file mode 100644 index 000000000..92e9f1f4a --- /dev/null +++ b/ros2bag/ros2bag/verb/play.py @@ -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) diff --git a/ros2bag/ros2bag/verb/record.py b/ros2bag/ros2bag/verb/record.py new file mode 100644 index 000000000..66741d568 --- /dev/null +++ b/ros2bag/ros2bag/verb/record.py @@ -0,0 +1,35 @@ +# 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 RecordVerb(VerbExtension): + """ros2 bag record.""" + + def add_arguments(self, parser, cli_name): # noqa: D102 + 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 + + topics = 'all' if args.all else args.topics + print('topics to be recorded:', topics) diff --git a/ros2bag/setup.py b/ros2bag/setup.py new file mode 100644 index 000000000..fcf908a86 --- /dev/null +++ b/ros2bag/setup.py @@ -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', + ], + } +) From 0bc253d0f0ae986935717e3f1e3cec5a5f6d7297 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Fri, 6 Jul 2018 17:46:05 -0700 Subject: [PATCH 2/5] get available topics --- ros2bag/ros2bag/verb/record.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ros2bag/ros2bag/verb/record.py b/ros2bag/ros2bag/verb/record.py index 66741d568..2d5133501 100644 --- a/ros2bag/ros2bag/verb/record.py +++ b/ros2bag/ros2bag/verb/record.py @@ -13,6 +13,10 @@ # 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 @@ -21,6 +25,7 @@ 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( @@ -31,5 +36,11 @@ def main(self, *, args): # noqa: D102 print('invalid choice: Can not specify topics and -a at the same time') return - topics = 'all' if args.all else args.topics - print('topics to be recorded:', topics) + 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) From 132b265caecb33f63cc798afd28c6b1830aa69d3 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Tue, 7 Aug 2018 09:27:38 -0700 Subject: [PATCH 3/5] remove rclpy dependency --- ros2bag/package.xml | 1 - ros2bag/ros2bag/api/__init__.py | 17 ----------------- 2 files changed, 18 deletions(-) diff --git a/ros2bag/package.xml b/ros2bag/package.xml index 4d70ccb64..f8bfa3eab 100644 --- a/ros2bag/package.xml +++ b/ros2bag/package.xml @@ -9,7 +9,6 @@ Karsten Knese Apache License 2.0 - rclpy ros2cli python3-yaml diff --git a/ros2bag/ros2bag/api/__init__.py b/ros2bag/ros2bag/api/__init__.py index dab5079fa..e69de29bb 100644 --- a/ros2bag/ros2bag/api/__init__.py +++ b/ros2bag/ros2bag/api/__init__.py @@ -1,17 +0,0 @@ -# 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 rclpy - - From f14b590a57e2a7803c7487b2ca482dd306e8d8b6 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Tue, 7 Aug 2018 16:16:43 -0700 Subject: [PATCH 4/5] add disclaimer --- ros2bag/ros2bag/command/bag.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ros2bag/ros2bag/command/bag.py b/ros2bag/ros2bag/command/bag.py index d64f0016b..5bac45237 100644 --- a/ros2bag/ros2bag/command/bag.py +++ b/ros2bag/ros2bag/command/bag.py @@ -36,5 +36,7 @@ def main(self, *, parser, args): 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) From d228beb702faf084eb58a260b32ba2c3c3e201c9 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Tue, 7 Aug 2018 16:41:42 -0700 Subject: [PATCH 5/5] remove yaml dependency --- ros2bag/package.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/ros2bag/package.xml b/ros2bag/package.xml index f8bfa3eab..3f1a5e943 100644 --- a/ros2bag/package.xml +++ b/ros2bag/package.xml @@ -11,8 +11,6 @@ ros2cli - python3-yaml - ament_copyright ament_flake8 ament_pep257