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..3f1a5e943 100644 --- a/ros2bag/package.xml +++ b/ros2bag/package.xml @@ -3,18 +3,20 @@ 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 - ros2cli - ament_lint_auto - ament_lint_common + 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..e69de29bb 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..5bac45237 --- /dev/null +++ b/ros2bag/ros2bag/command/bag.py @@ -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) 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..2d5133501 --- /dev/null +++ b/ros2bag/ros2bag/verb/record.py @@ -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) 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', + ], + } +)