Skip to content

Commit a9945c9

Browse files
committed
cras_bag_tools: Added Copy filter.
1 parent dc12911 commit a9945c9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

cras_bag_tools/src/cras_bag_tools/message_filters.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,39 @@ def process_cli_args(filters, args):
240240
filters.append(Remap(**dict(zip(topics_from, topics_to))))
241241

242242

243+
class Copy(RawMessageFilter):
244+
"""Copy topics to other topics."""
245+
246+
def __init__(self, **kwargs):
247+
"""
248+
:param dict kwargs: The mapping to use. Keys are topics to be copied, values are their new names.
249+
"""
250+
super(Copy, self).__init__(include_topics=kwargs.keys())
251+
self.copy = kwargs
252+
253+
def filter(self, topic, datatype, data, md5sum, pytype, stamp, header):
254+
return [
255+
(topic, datatype, data, md5sum, pytype, stamp, header),
256+
(self.copy.get(topic, topic), datatype, data, md5sum, pytype, stamp, header),
257+
]
258+
259+
def _str_params(self):
260+
return dict_to_str(self.copy, '=>')
261+
262+
@staticmethod
263+
def add_cli_args(parser):
264+
parser.add_argument(
265+
'--copy', nargs='+', metavar="FROM TO",
266+
help="Copy topics. This argument should be an even-sized list of pairs [FROM TO].")
267+
268+
@staticmethod
269+
def process_cli_args(filters, args):
270+
if args.remap:
271+
topics_from = args.remap[0::2]
272+
topics_to = args.remap[1::2]
273+
filters.append(Copy(**dict(zip(topics_from, topics_to))))
274+
275+
243276
class Throttle(RawMessageFilter):
244277
"""Throttle messages on topics."""
245278

0 commit comments

Comments
 (0)