Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial command line interface #12

Merged
merged 5 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ros2bag/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*__pycache__*
33 changes: 0 additions & 33 deletions ros2bag/CMakeLists.txt

This file was deleted.

16 changes: 9 additions & 7 deletions ros2bag/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
<package format="2">
<name>ros2bag</name>
<version>0.0.0</version>
<description>ROSBag2 verb for ros2cli</description>
<maintainer email="[email protected]">Karsten Knese</maintainer>
<description>
Entry point for rosbag in ROS 2
</description>
<maintainer email="[email protected]">Karsten Knese</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>ros2cli</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_cmake</build_type>
<build_type>ament_python</build_type>
</export>
</package>
Empty file added ros2bag/ros2bag/__init__.py
Empty file.
Empty file.
Empty file.
42 changes: 42 additions & 0 deletions ros2bag/ros2bag/command/bag.py
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)
44 changes: 44 additions & 0 deletions ros2bag/ros2bag/verb/__init__.py
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()
29 changes: 29 additions & 0 deletions ros2bag/ros2bag/verb/info.py
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)
27 changes: 27 additions & 0 deletions ros2bag/ros2bag/verb/play.py
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)
46 changes: 46 additions & 0 deletions ros2bag/ros2bag/verb/record.py
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)
39 changes: 39 additions & 0 deletions ros2bag/setup.py
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='[email protected]',
maintainer='Karsten Knese',
maintainer_email='[email protected]',
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',
],
}
)