1
1
#!/usr/bin/python
2
2
"""View the output from osg-test in a structured way"""
3
+ from __future__ import print_function
3
4
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
6
10
import os
7
11
import re
8
12
import subprocess
9
13
import sys
10
- import urllib2
11
- import tkFont
12
14
13
15
14
16
@@ -23,7 +25,7 @@ class Section(object):
23
25
24
26
def is_empty (text ):
25
27
"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 )
27
29
28
30
29
31
def load_logdata_from_handle (handle ):
@@ -35,7 +37,8 @@ def load_logdata_from_handle(handle):
35
37
current_test = ""
36
38
37
39
for line in handle :
38
- line = line .rstrip ()
40
+ if six .PY3 :
41
+ line = line .decode (errors = "replace" ).rstrip ()
39
42
command_match = re .match (r'(?x)osgtest: \s* ' + datetime_re + r''': \s*
40
43
(?P<test>[^:]+:[^:]+):
41
44
(?P<lineno>\d+): \s*
@@ -76,25 +79,19 @@ def load_logdata_from_handle(handle):
76
79
77
80
def load_logdata_from_file (filename ):
78
81
try :
79
- filehandle = open (filename , 'r' )
80
- try :
82
+ with open (filename ) as filehandle :
81
83
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 )
86
86
sys .exit (1 )
87
87
88
88
89
89
def load_logdata_from_url (url ):
90
90
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 )
98
95
sys .exit (1 )
99
96
100
97
@@ -179,8 +176,8 @@ class Application(Frame):
179
176
180
177
def main ():
181
178
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" )
184
181
sys .exit (2 )
185
182
logpath = sys .argv [1 ]
186
183
if '://' not in logpath :
0 commit comments