Skip to content

Commit 8dd3b45

Browse files
committed
Add python 3 compat to osg-test-log-viewer
1 parent 0008dab commit 8dd3b45

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

osg-test-log-viewer

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/python
22
"""View the output from osg-test in a structured way"""
3+
from __future__ import print_function
34

4-
from Tkinter import *
5-
import ScrolledText
5+
import six
6+
from six.moves.tkinter import *
7+
from six.moves import tkinter_scrolledtext as ScrolledText
8+
from six.moves import tkinter_font as tkFont
9+
from six.moves import urllib
610
import os
711
import re
812
import subprocess
913
import sys
10-
import urllib2
11-
import tkFont
1214

1315

1416

@@ -23,7 +25,7 @@ class Section(object):
2325

2426
def is_empty(text):
2527
"True if a block of text is empty except for whitespace"
26-
return not re.search('\S', text)
28+
return not re.search(r'\S', text)
2729

2830

2931
def load_logdata_from_handle(handle):
@@ -35,7 +37,8 @@ def load_logdata_from_handle(handle):
3537
current_test = ""
3638

3739
for line in handle:
38-
line = line.rstrip()
40+
if six.PY3:
41+
line = line.decode(errors="replace").rstrip()
3942
command_match = re.match(r'(?x)osgtest: \s* ' + datetime_re + r''': \s*
4043
(?P<test>[^:]+:[^:]+):
4144
(?P<lineno>\d+): \s*
@@ -76,25 +79,19 @@ def load_logdata_from_handle(handle):
7679

7780
def load_logdata_from_file(filename):
7881
try:
79-
filehandle = open(filename, 'r')
80-
try:
82+
with open(filename) as filehandle:
8183
return load_logdata_from_handle(filehandle)
82-
finally:
83-
filehandle.close()
84-
except IOError, e:
85-
print >> sys.stderr, "Error reading file %s: %s" % (filename, e.strerror)
84+
except IOError as e:
85+
print("Error reading file %s: %s" % (filename, e.strerror), file=sys.stderr)
8686
sys.exit(1)
8787

8888

8989
def load_logdata_from_url(url):
9090
try:
91-
urlhandle = urllib2.urlopen(url)
92-
try:
93-
return load_logdata_from_handle(urlhandle)
94-
finally:
95-
urlhandle.close()
96-
except urllib2.URLError, e:
97-
print >> sys.stderr, "Error reading URL %s: %s" % (url, e.strerror)
91+
urlhandle = urllib.request.urlopen(url)
92+
return load_logdata_from_handle(urlhandle)
93+
except urllib.error as e:
94+
print("Error reading URL %s: %s" % (url, e.strerror), file=sys.stderr)
9895
sys.exit(1)
9996

10097

@@ -179,8 +176,8 @@ class Application(Frame):
179176

180177
def main():
181178
if len(sys.argv) != 2:
182-
print "Usage: %s <LOG FILENAME OR URL>" % sys.argv[0]
183-
print "View the output of osg-test"
179+
print("Usage: %s <LOG FILENAME OR URL>" % sys.argv[0])
180+
print("View the output of osg-test")
184181
sys.exit(2)
185182
logpath = sys.argv[1]
186183
if '://' not in logpath:

0 commit comments

Comments
 (0)