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