29
29
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
30
"""
31
31
32
- import rospy
32
+ from __future__ import print_function
33
+
33
34
import rosbag
34
35
35
36
import argparse
36
37
import os
38
+ import sys
37
39
38
40
def merge (inbags , outbag = 'output.bag' , topics = None , exclude_topics = [], raw = True ):
39
41
# Open output bag file:
40
42
try :
41
43
out = rosbag .Bag (outbag , 'a' if os .path .exists (outbag ) else 'w' )
42
44
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
46
47
47
48
# Write the messages from the input bag files into the output one:
48
49
for inbag in inbags :
49
50
try :
50
- rospy . loginfo (' Processing input bagfile: %s' , inbag )
51
+ print (' Processing input bagfile: %s' % inbag )
51
52
for topic , msg , t in rosbag .Bag (inbag , 'r' ).read_messages (topics = topics , raw = raw ):
52
53
if topic not in args .exclude_topics :
53
54
out .write (topic , msg , t , raw = raw )
54
55
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
58
58
59
59
out .close ()
60
60
61
+ return 0
61
62
62
- if __name__ == "__main__" :
63
- rospy .init_node ('merge' , anonymous = True )
64
63
64
+ if __name__ == "__main__" :
65
65
parser = argparse .ArgumentParser (
66
66
description = 'Merge multiple bag files into a single one.' )
67
67
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)
71
71
args = parser .parse_args ()
72
72
73
73
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 ) )
75
75
except Exception , e :
76
76
import traceback
77
77
traceback .print_exc ()
0 commit comments