merge.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # Copied from https://raw.githubusercontent.com/srv/srv_tools/kinetic/bag_tools/scripts/merge.py since this script is
3 # not released for kinetic.
4 """
5 Copyright (c) 2015,
6 Enrique Fernandez Perdomo
7 Clearpath Robotics, Inc.
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12  * Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions and the following disclaimer in the
16  documentation and/or other materials provided with the distribution.
17  * Neither the name of Systems, Robotics and Vision Group, University of
18  the Balearican Islands nor the names of its contributors may be used to
19  endorse or promote products derived from this software without specific
20  prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
26 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 """
33 
34 from __future__ import print_function
35 
36 import rosbag
37 
38 import argparse
39 import os
40 import sys
41 
42 def merge(inbags, outbag='output.bag', topics=None, exclude_topics=[], raw=True):
43  # Open output bag file:
44  try:
45  out = rosbag.Bag(outbag, 'a' if os.path.exists(outbag) else 'w')
46  except IOError as e:
47  print('Failed to open output bag file %s!: %s' % (outbag, e.message), file=sys.stderr)
48  return 127
49 
50  # Write the messages from the input bag files into the output one:
51  for inbag in inbags:
52  try:
53  print(' Processing input bagfile: %s' % inbag)
54  for topic, msg, t in rosbag.Bag(inbag, 'r').read_messages(topics=topics, raw=raw):
55  if topic not in args.exclude_topics:
56  out.write(topic, msg, t, raw=raw)
57  except IOError as e:
58  print('Failed to open input bag file %s!: %s' % (inbag, e.message), file=sys.stderr)
59  return 127
60 
61  out.close()
62 
63  return 0
64 
65 
66 if __name__ == "__main__":
67  parser = argparse.ArgumentParser(
68  description='Merge multiple bag files into a single one.')
69  parser.add_argument('inbag', help='input bagfile(s)', nargs='+')
70  parser.add_argument('--output', help='output bag file', default='output.bag')
71  parser.add_argument('--topics', help='topics to merge from the input bag files', nargs='+', default=None)
72  parser.add_argument('--exclude_topics', help='topics not to merge from the input bag files', nargs='+', default=[])
73  args = parser.parse_args()
74 
75  try:
76  sys.exit(merge(args.inbag, args.output, args.topics, args.exclude_topics))
77  except Exception, e:
78  import traceback
79  traceback.print_exc()
Definition: merge.py:1
def merge(inbags, outbag='output.bag', topics=None, exclude_topics=[], raw=True)
Definition: merge.py:42


movie_publisher
Author(s): Martin Pecka
autogenerated on Sat Jul 18 2020 03:15:30