Commit 7521f4cf authored by Vincent Pelletier's avatar Vincent Pelletier

Add an argument to disable progress output to stderr.

parent 034faedd
......@@ -939,6 +939,8 @@ def main():
help='Filename to write output to. Use - for stdout. Default: %(default)s')
parser.add_argument('-q', '--quiet', action='store_true',
help='Suppress warnings about malformed lines.')
parser.add_argument('-Q', dest='extra_quiet', action='store_true',
help='Suppress progress indication (file being parsed, lines counter)')
parser.add_argument('--state-file', nargs='+', default=[], type=file,
help='Use given JSON files as initial state. Mixing files generated with '
'different parameters is allowed, but no correction is made. Output may '
......@@ -1110,10 +1112,12 @@ def main():
no_url_lines = 0
all_lines = 0
skipped_user_agent = 0
show_progress = not args.extra_quiet
start_time = time.time()
for fileno, filename in enumerate(infile_list, 1):
print >> sys.stderr, 'Processing %s [%i/%i]' % (
filename, fileno, file_count)
if show_progress:
print >> sys.stderr, 'Processing %s [%i/%i]' % (
filename, fileno, file_count)
if filename == '-':
logfile = sys.stdin
else:
......@@ -1130,9 +1134,8 @@ def main():
logfile = open(filename)
lineno = 0
for lineno, line in enumerate(logfile, 1):
if lineno % 5000 == 0:
sys.stderr.write('%i\r' % lineno)
sys.stderr.flush()
if show_progress and lineno % 5000 == 0:
print >> sys.stderr, '%i\r',
match = matchline(line)
if match is None:
match = expensive_matchline(line)
......@@ -1176,15 +1179,17 @@ def main():
next_period = getNextPeriod()
except StopIteration:
pass
print >> sys.stderr, 'Increasing period to', period, '...',
if show_progress:
print >> sys.stderr, 'Increasing period to', period, '...',
old_date_format = date_format
asDate, decimator, graph_period, date_format, placeholder_delta, \
round_date = period_parser[period]
period_increase_start = time.time()
for site_data in per_site.itervalues():
site_data.rescale(rescale, getDuration)
print >> sys.stderr, 'done (%s)' % timedelta(seconds=time.time()
- period_increase_start)
if show_progress:
print >> sys.stderr, 'done (%s)' % timedelta(seconds=time.time()
- period_increase_start)
date = asDate(match.group('timestamp'))
try:
site_data = per_site[site]
......@@ -1193,7 +1198,8 @@ def main():
error_detail=error_detail)
site_data.accumulate(match, url_match, date)
all_lines += lineno
sys.stderr.write('%i\n' % lineno)
if show_progress:
print >> sys.stderr, lineno
end_parsing_time = time.time()
generator, out_encoding = format_generator[args.format]
if args.out == '-':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment