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

Toward Python3: print_function

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