rosbag: harden 'rosbag info'
This commit is contained in:
parent
fc5e03e693
commit
bc78523fae
|
@ -481,7 +481,8 @@ class Bag(object):
|
|||
|
||||
def _open_read(self, f):
|
||||
if isinstance(f, file):
|
||||
self._file = f
|
||||
self._file = f
|
||||
self._filename = None
|
||||
else:
|
||||
self._file = open(f, 'rb')
|
||||
self._filename = f
|
||||
|
@ -504,7 +505,8 @@ class Bag(object):
|
|||
|
||||
def _open_write(self, f):
|
||||
if isinstance(f, file):
|
||||
self._file = f
|
||||
self._file = f
|
||||
self._filename = None
|
||||
else:
|
||||
self._file = open(f, 'wb')
|
||||
self._filename = f
|
||||
|
@ -519,7 +521,8 @@ class Bag(object):
|
|||
|
||||
def _open_append(self, f):
|
||||
if isinstance(f, file):
|
||||
self._file = f
|
||||
self._file = f
|
||||
self._filename = None
|
||||
else:
|
||||
try:
|
||||
# Test if the file already exists.
|
||||
|
@ -551,7 +554,7 @@ class Bag(object):
|
|||
except:
|
||||
self._close_file()
|
||||
raise
|
||||
|
||||
|
||||
def _close_file(self):
|
||||
self._file.close()
|
||||
self._file = None
|
||||
|
@ -588,7 +591,7 @@ class Bag(object):
|
|||
|
||||
matches = re.match("#ROS(.*) V(\d).(\d)", version_line)
|
||||
if matches is None or len(matches.groups()) != 3:
|
||||
raise ROSBagException('rosbag does not support %s' % version_line)
|
||||
raise ROSBagException('This does not appear to be a bag file')
|
||||
|
||||
version_type, major_version_str, minor_version_str = matches.groups()
|
||||
|
||||
|
|
|
@ -32,22 +32,26 @@
|
|||
#
|
||||
# Revision $Id$
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
import signal
|
||||
import subprocess
|
||||
import optparse
|
||||
from optparse import OptionParser
|
||||
import sys
|
||||
|
||||
from bag import Bag
|
||||
from bag import Bag, ROSBagException
|
||||
|
||||
def info_cmd(argv):
|
||||
parser = OptionParser(usage='rosbag info BAGFILE1 [BAGFILE2 BAGFILE3 ...]', description='Summarize the contents of one or more bag files.')
|
||||
parser = optparse.OptionParser(usage='rosbag info BAGFILE1 [BAGFILE2 BAGFILE3 ...]', description='Summarize the contents of one or more bag files.')
|
||||
(options, args) = parser.parse_args(argv)
|
||||
|
||||
if len(args) == 0:
|
||||
parser.error('You must specify at least 1 bag file.')
|
||||
|
||||
for i, arg in enumerate(args):
|
||||
print Bag(arg)
|
||||
if i < len(args) - 1:
|
||||
print '---'
|
||||
try:
|
||||
print Bag(arg)
|
||||
if i < len(args) - 1:
|
||||
print '---'
|
||||
except ROSBagException, ex:
|
||||
print >> sys.stderr, 'ERROR: %s' % str(ex)
|
||||
except IOError, ex:
|
||||
print >> sys.stderr, 'ERROR: %s' % str(ex)
|
||||
|
|
Loading…
Reference in New Issue