Skip to content

Commit 029cef4

Browse files
Merge pull request #123 from matyasselmeci/wip/py3
Python 3 compatibility for osg-test-log-viewer
2 parents 0008dab + 032dc0b commit 029cef4

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

osg-test-log-viewer

Lines changed: 18 additions & 20 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,6 +37,8 @@ def load_logdata_from_handle(handle):
3537
current_test = ""
3638

3739
for line in handle:
40+
if six.PY3:
41+
line = line.decode(errors="replace")
3842
line = line.rstrip()
3943
command_match = re.match(r'(?x)osgtest: \s* ' + datetime_re + r''': \s*
4044
(?P<test>[^:]+:[^:]+):
@@ -76,25 +80,19 @@ def load_logdata_from_handle(handle):
7680

7781
def load_logdata_from_file(filename):
7882
try:
79-
filehandle = open(filename, 'r')
80-
try:
83+
with open(filename) as filehandle:
8184
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)
85+
except IOError as e:
86+
print("Error reading file %s: %s" % (filename, e.strerror), file=sys.stderr)
8687
sys.exit(1)
8788

8889

8990
def load_logdata_from_url(url):
9091
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)
92+
urlhandle = urllib.request.urlopen(url)
93+
return load_logdata_from_handle(urlhandle)
94+
except urllib.error as e:
95+
print("Error reading URL %s: %s" % (url, e.strerror), file=sys.stderr)
9896
sys.exit(1)
9997

10098

@@ -179,8 +177,8 @@ class Application(Frame):
179177

180178
def main():
181179
if len(sys.argv) != 2:
182-
print "Usage: %s <LOG FILENAME OR URL>" % sys.argv[0]
183-
print "View the output of osg-test"
180+
print("Usage: %s <LOG FILENAME OR URL>" % sys.argv[0])
181+
print("View the output of osg-test")
184182
sys.exit(2)
185183
logpath = sys.argv[1]
186184
if '://' not in logpath:

rpm/osg-test.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ installation.
2121
Summary: Views the output of %{name}
2222
Group: Applications/Grid
2323
Requires: tkinter
24+
Requires: python-six
2425

2526
%description log-viewer
2627
A GUI for viewing the output of %{name} in a structured manner.

0 commit comments

Comments
 (0)