rosbag: fix decompress progress bar #2853

This commit is contained in:
Tim Field 2010-07-07 19:51:33 +00:00
parent 810d72c7d6
commit 2ee5c8d3c3
2 changed files with 33 additions and 37 deletions

View File

@ -108,7 +108,7 @@ class Bag(object):
@type chunk_threshold: int
@param allow_unindexed: if True, allow opening unindexed bags
@type allow_unindexed: bool
@param options: the bag options (currently, compression and chunk_threshold)
@param options: the bag options (currently: compression and chunk_threshold)
@type options: dict
@raise ValueError: if any argument is invalid
@raise ROSBagException: if an error occurs opening file
@ -226,10 +226,10 @@ class Bag(object):
@type end_time: U{roslib.rostime.Time}
@param connection_filter: function to filter connections to include [optional]
@type connection_filter: function taking (topic, datatype, md5sum, msg_def, header) and returning bool
@param raw: if True, then generate tuples of (datatype, data, md5sum, position, pytype)
@param raw: if True, then generate tuples of (datatype, (data, md5sum, position), pytype)
@type raw: bool
@return: generator of (topic, message, timestamp) tuples for each message in the bag file
@rtype: generator of tuples of (topic, message, timestamp)
@rtype: generator of tuples of (str, U{roslib.message.Message}, U{roslib.rostime.Time}) [not raw] or (str, (str, str, str, tuple, class), U{roslib.rostime.Time}) [raw]
"""
self.flush()
@ -700,6 +700,13 @@ class Bag(object):
### Internal API ###
@property
def _uncompressed_size(self):
if not self._chunk_headers:
return self.size
return sum((h.uncompressed_size for h in self._chunk_headers.values()))
def _read_message(self, position, raw=False):
"""
Read the message from the given position in the file.
@ -884,7 +891,7 @@ class Bag(object):
# File exists: open in read with update mode
self._file = open(f, 'r+b')
except:
except IOError:
# File doesn't exist: open in write mode
self._file = open(f, 'w+b')
@ -1516,7 +1523,7 @@ class _BagReader102_Unindexed(_BagReader):
try:
header = _read_header(f)
except:
except Exception:
return
op = _read_uint8_field(header, 'op')
@ -1940,7 +1947,7 @@ class _BagReader200(_BagReader):
connection_index = self.bag._connection_indexes[connection_id]
for entry in index:
connection_index.append(entry)
except:
except Exception:
raise ROSBagUnindexedException()
def read_messages(self, topics, start_time, end_time, connection_filter, raw):

View File

@ -58,18 +58,17 @@ def record_cmd(argv):
description="Record a bag file with the contents of specified topics.",
formatter=optparse.IndentedHelpFormatter())
parser.add_option("-a", "--all", dest="all", default=False, action="store_true", help="record all topics")
parser.add_option("-e", "--regex", dest="regex", default=False, action="store_true", help="match topics using regular expressions")
parser.add_option("-x", "--exclude", dest="exclude_regex", default="", action="store",
help="Exclude topics matching the follow regular expression (subtracts from -a or regex)")
parser.add_option("-q", "--quiet", dest="quiet", default=False, action="store_true", help="suppress console output")
parser.add_option("-o", "--output-prefix", dest="prefix", default=None, action="store", help="prepend PREFIX to beginning of bag name (name will always end with date stamp)")
parser.add_option("-O", "--output-name", dest="name", default=None, action="store", help="record to bag with name NAME.bag")
parser.add_option("--split", dest="split", default=0, type='int', action="store", help="split bag into files of size SIZE", metavar="SIZE")
parser.add_option("-b", "--buffsize", dest="buffsize", default=256, type='int', action="store", help="use in internal buffer of SIZE MB (Default: %default, 0 = infinite)", metavar="SIZE")
parser.add_option("-l", "--limit", dest="num", default=0, type='int', action="store", help="only record NUM messages on each topic")
#parser.add_option("-z", "--zlib", dest="zlib", default=False, action="store_true", help="use ZLIB compression")
parser.add_option("-j", "--bz2", dest="bz2", default=False, action="store_true", help="use BZ2 compression")
parser.add_option("-a", "--all", dest="all", default=False, action="store_true", help="record all topics")
parser.add_option("-e", "--regex", dest="regex", default=False, action="store_true", help="match topics using regular expressions")
parser.add_option("-x", "--exclude", dest="exclude_regex", default="", action="store", help="Exclude topics matching the follow regular expression (subtracts from -a or regex)")
parser.add_option("-q", "--quiet", dest="quiet", default=False, action="store_true", help="suppress console output")
parser.add_option("-o", "--output-prefix", dest="prefix", default=None, action="store", help="prepend PREFIX to beginning of bag name (name will always end with date stamp)")
parser.add_option("-O", "--output-name", dest="name", default=None, action="store", help="record to bag with name NAME.bag")
parser.add_option( "--split", dest="split", default=0, type='int', action="store", help="split bag into files of size SIZE", metavar="SIZE")
parser.add_option("-b", "--buffsize", dest="buffsize", default=256, type='int', action="store", help="use in internal buffer of SIZE MB (Default: %default, 0 = infinite)", metavar="SIZE")
parser.add_option("-l", "--limit", dest="num", default=0, type='int', action="store", help="only record NUM messages on each topic")
parser.add_option("-j", "--bz2", dest="bz2", default=False, action="store_true", help="use BZ2 compression")
#parser.add_option("-z", "--zlib", dest="zlib", default=False, action="store_true", help="use ZLIB compression")
(options, args) = parser.parse_args(argv)
@ -85,24 +84,19 @@ help="Exclude topics matching the follow regular expression (subtracts from -a o
cmd.extend(['--limit', str(options.num)])
cmd.extend(['--split', str(options.split)])
if options.quiet: cmd.extend(["--quiet"])
if options.prefix: cmd.extend(["-o", options.prefix])
if options.name: cmd.extend(["-O", options.name])
if options.quiet: cmd.extend(["--quiet"])
if options.prefix: cmd.extend(["-o", options.prefix])
if options.name: cmd.extend(["-O", options.name])
if options.exclude_regex: cmd.extend(["--exclude", options.exclude_regex])
if options.all: cmd.extend(["--all"])
if options.regex: cmd.extend(["--regex"])
if options.bz2: cmd.extend(["--bz2"])
if options.all: cmd.extend(["--all"])
if options.regex: cmd.extend(["--regex"])
if options.bz2: cmd.extend(["--bz2"])
cmd.extend(args)
recordpath = os.path.join(roslib.rospack.rospackexec(['find', 'rosbag']), 'bin', 'record')
os.execv(recordpath, cmd)
# proc = subprocess.Popen(cmd)
# signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore sigint since we're basically just pretending to be the subprocess now
# res = proc.wait()
# sys.exit(res)
def info_cmd(argv):
parser = optparse.OptionParser(usage='rosbag info [options] BAGFILE1 [BAGFILE2 BAGFILE3 ...]',
description='Summarize the contents of one or more bag files.')
@ -180,11 +174,6 @@ def play_cmd(argv):
playpath = os.path.join(roslib.rospack.rospackexec(['find', 'rosbag']), 'bin', 'play')
os.execv(playpath, cmd)
# proc = subprocess.Popen(cmd)
# signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore sigint since we're basically just pretending to be the subprocess now
# res = proc.wait()
# sys.exit(res)
def filter_cmd(argv):
def expr_eval(expr):
def eval_fn(topic, m, t):
@ -574,9 +563,9 @@ def change_compression_op(inbag, outbag, compression, quiet):
if quiet:
for topic, msg, t in inbag.read_messages(raw=True):
outbag.write(topic, msg, t, raw=True)
else:
meter = ProgressMeter(outbag.filename, inbag.size)
else:
meter = ProgressMeter(outbag.filename, inbag._uncompressed_size)
total_bytes = 0
for topic, msg, t in inbag.read_messages(raw=True):
msg_type, serialized_bytes, md5sum, pos, pytype = msg