Commit 5c4d3570 authored by Vincent Pelletier's avatar Vincent Pelletier

Toward Python3: print_function

parent 16c75a95
......@@ -26,6 +26,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from __future__ import print_function
from cgi import escape
from collections import defaultdict, Counter
from datetime import datetime, timedelta, date
......@@ -1241,7 +1242,7 @@ def main():
parser.error('stdin cannot be used both as log and state input.')
loading_start_time = time.time()
for state_file_name in args.state_file:
print >> sys.stderr, 'Loading', state_file_name, '...',
print('Loading %s...' % state_file_name, end='', file=sys.stderr)
if state_file_name == '-':
state_file = sys.stdin
else:
......@@ -1261,7 +1262,8 @@ def main():
site = None
action = default_action
if action is None:
print >> sys.stderr, 'Info: no prefix match %r, stats skipped' % url
print('Info: no prefix match %r, stats skipped' % url,
file='sys.stderr')
continue
site_stats = action.func.fromJSONState(site_state,
getDuration, action.keywords['suffix'])
......@@ -1269,8 +1271,8 @@ def main():
per_site[site].accumulateFrom(site_stats)
else:
per_site[site] = site_stats
print >> sys.stderr, 'done (%s)' % timedelta(seconds=time.time()
- load_start)
print('done (%s)' % timedelta(seconds=time.time() - load_start),
file=sys.stderr)
skip_user_agent = list(itertools.chain(*args.skip_user_agent))
malformed_lines = 0
skipped_lines = 0
......@@ -1281,8 +1283,8 @@ def main():
parsing_start_time = time.time()
for fileno, filename in enumerate(infile_list, 1):
if show_progress:
print >> sys.stderr, 'Processing %s [%i/%i]' % (
filename, fileno, file_count)
print('Processing %s [%i/%i]' % (filename, fileno, file_count),
file=sys.stderr)
if filename == '-':
logfile = sys.stdin
else:
......@@ -1300,14 +1302,14 @@ def main():
lineno = 0
for lineno, line in enumerate(logfile, 1):
if show_progress and lineno % 5000 == 0:
print >> sys.stderr, lineno, '\r',
print(lineno, end='\r', file=sys.stderr)
match = matchline(line)
if match is None:
match = expensive_matchline(line)
if match is None:
if not quiet:
print >> sys.stderr, 'Malformed line at %s:%i: %r' % (
filename, lineno, line)
print('Malformed line at %s:%i: %r' % (filename, lineno, line),
file=sys.stderr)
malformed_lines += 1
continue
if match.group('agent') in skip_user_agent:
......@@ -1346,7 +1348,8 @@ def main():
if original_period != period:
original_period = period
if show_progress:
print >> sys.stderr, 'Increasing period to', period, '...',
print('Increasing period to %s...' % period, end='',
file=sys.stderr)
old_date_format = date_format
asDate, decimator, graph_period, date_format, placeholder_delta, \
round_date, graph_coefficient = period_parser[period]
......@@ -1356,8 +1359,8 @@ def main():
for site_data in per_site.itervalues():
site_data.rescale(rescale, getDuration)
if show_progress:
print >> sys.stderr, 'done (%s)' % timedelta(seconds=time.time()
- period_increase_start)
print('done (%s)' % timedelta(seconds=time.time()
- period_increase_start), file=sys.stderr)
hit_date = asDate(match.group('timestamp'))
try:
site_data = per_site[site]
......@@ -1368,12 +1371,12 @@ def main():
site_data.accumulate(match, url_match, hit_date)
except Exception:
if not quiet:
print >> sys.stderr, 'Error analysing line at %s:%i: %r' % (filename,
lineno, line)
print('Error analysing line at %s:%i: %r' % (filename, lineno, line),
file=sys.stderr)
traceback.print_exc(file=sys.stderr)
all_lines += lineno
if show_progress:
print >> sys.stderr, lineno
print(lineno, file=sys.stderr)
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