Skip to content

Commit 0b29632

Browse files
author
Enrique Fernandez
committed
Make merge.py ROS-agnostic
1 parent 90644d6 commit 0b29632

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

bag_tools/scripts/merge.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,39 @@
2929
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
"""
3131

32-
import rospy
32+
from __future__ import print_function
33+
3334
import rosbag
3435

3536
import argparse
3637
import os
38+
import sys
3739

3840
def merge(inbags, outbag='output.bag', topics=None, exclude_topics=[], raw=True):
3941
# Open output bag file:
4042
try:
4143
out = rosbag.Bag(outbag, 'a' if os.path.exists(outbag) else 'w')
4244
except IOError as e:
43-
rospy.logerr('Failed to open output bag file %s!: %s' % (outbag, e.message))
44-
rospy.signal_shutdown('Failed to open output bag file %s!: %s' % (outbag, e.message))
45-
return
45+
print('Failed to open output bag file %s!: %s' % (outbag, e.message), file=sys.stderr)
46+
return 127
4647

4748
# Write the messages from the input bag files into the output one:
4849
for inbag in inbags:
4950
try:
50-
rospy.loginfo(' Processing input bagfile: %s', inbag)
51+
print(' Processing input bagfile: %s' % inbag)
5152
for topic, msg, t in rosbag.Bag(inbag, 'r').read_messages(topics=topics, raw=raw):
5253
if topic not in args.exclude_topics:
5354
out.write(topic, msg, t, raw=raw)
5455
except IOError as e:
55-
rospy.logerr('Failed to open input bag file %s!: %s' % (inbag, e.message))
56-
rospy.signal_shutdown('Failed to open input bag file %s!: %s' % (inbag, e.message))
57-
return
56+
print('Failed to open input bag file %s!: %s' % (inbag, e.message), file=sys.stderr)
57+
return 127
5858

5959
out.close()
6060

61+
return 0
6162

62-
if __name__ == "__main__":
63-
rospy.init_node('merge', anonymous=True)
6463

64+
if __name__ == "__main__":
6565
parser = argparse.ArgumentParser(
6666
description='Merge multiple bag files into a single one.')
6767
parser.add_argument('inbag', help='input bagfile(s)', nargs='+')
@@ -71,7 +71,7 @@ def merge(inbags, outbag='output.bag', topics=None, exclude_topics=[], raw=True)
7171
args = parser.parse_args()
7272

7373
try:
74-
merge(args.inbag, args.output, args.topics, args.exclude_topics)
74+
sys.exit(merge(args.inbag, args.output, args.topics, args.exclude_topics))
7575
except Exception, e:
7676
import traceback
7777
traceback.print_exc()

0 commit comments

Comments
 (0)