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

added prefix verb and filter #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ros2bag_tools adds verb extensions to the ros2bag cli.
| plot | plot message data to a new window, see [plot](#plot) |
| process | chain multiple filters, see [chaining](#chaining) |
| **prune** | remove topics without messages |
| **prefix** | add a fixed prefix to all topics inside a bag file |
| **reframe** | change frame_id on messages with headers |
| **rename** | change name of a topic |
| **replace** | replace messages of a specific topic with message data specified in a yaml file |
Expand Down
43 changes: 43 additions & 0 deletions ros2bag_tools/ros2bag_tools/filter/prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2021 AIT Austrian Institute of Technology GmbH
#
# 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_tools.filter import FilterExtension


class PrefixAppendFilter(FilterExtension):

def __init__(self):
self._topic = None
self._new_name = None

def add_arguments(self, parser):
parser.add_argument('-p', '--prefix', help='prefix to add')
# parser.add_argument('--name', required=True, help='new name to set')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove leftover code comments


def set_args(self, _metadata, args):
self._prefix = args.prefix

def _add_prefix(self, topic_name):
return f"{self._prefix}{topic_name}"

def filter_topic(self, topic_metadata):
# if topic_metadata.name == self._topic:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove leftover code comments


topic_metadata.name = self._add_prefix(topic_metadata.name)
return topic_metadata

def filter_msg(self, msg):
(topic, data, t) = msg

return (self._add_prefix(topic), data, t)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing newline here

23 changes: 23 additions & 0 deletions ros2bag_tools/ros2bag_tools/verb/prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021 AIT Austrian Institute of Technology GmbH
#
# 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_tools.filter.prefix import PrefixAppendFilter
from ros2bag_tools.verb import FilterVerb


class PrefixVerb(FilterVerb):
"""Rename specific topics in a bag, and write to new bag."""

def __init__(self):
FilterVerb.__init__(self, PrefixAppendFilter())
2 changes: 2 additions & 0 deletions ros2bag_tools/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'export = ros2bag_tools.verb.export:ExportVerb',
'extract = ros2bag_tools.verb.extract:ExtractVerb',
'plot = ros2bag_tools.verb.plot:PlotVerb',
'prefix = ros2bag_tools.verb.prefix:PrefixVerb',
'prune = ros2bag_tools.verb.prune:PruneVerb',
'reframe = ros2bag_tools.verb.reframe:ReframeVerb',
'rename = ros2bag_tools.verb.rename:RenameVerb',
Expand All @@ -55,6 +56,7 @@
'drop = ros2bag_tools.filter.drop:DropFilter',
'extract = ros2bag_tools.filter.extract:ExtractFilter',
'image = ros2bag_tools.filter.image:ImageFilter',
'prefix = ros2bag_tools.filter.prefix:PrefixAppendFilter',
'prune = ros2bag_tools.filter.prune:PruneFilter',
'reframe = ros2bag_tools.filter.reframe:ReframeFilter',
'rename = ros2bag_tools.filter.rename:RenameFilter',
Expand Down