Skip to content

Commit 36715da

Browse files
Merge pull request #161 from matyasselmeci/pr/cmdhighlight
Fixes for osg-test-log-viewer
2 parents 8899b64 + 6b9f95a commit 36715da

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

osg-test-log-viewer

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ from six.moves.tkinter import *
77
from six.moves import tkinter_scrolledtext as ScrolledText
88
from six.moves import tkinter_font as tkFont
99
from six.moves import urllib
10-
import os
1110
import re
12-
import subprocess
1311
import sys
1412

1513

14+
OK_FAIL_COMMAND_PATTERNS = [
15+
# These commands don't get highlighted if they return nonzero
16+
"rpm --query",
17+
"systemctl is-active",
18+
r"service\s+\S+\s+status"
19+
]
1620

1721

1822
class Section(object):
@@ -63,10 +67,10 @@ def load_logdata_from_handle(handle):
6367
current_test = match.group('test')
6468

6569
retcode, _, _ = match.group('result').split()
66-
if int(retcode) != 0 and 'rpm --query' not in match.group('command'):
67-
color = "red"
68-
else:
69-
color = "black"
70+
color = "black"
71+
if int(retcode) != 0:
72+
if not any(re.search(pattern, match.group('command')) for pattern in OK_FAIL_COMMAND_PATTERNS):
73+
color = "red"
7074
section = Section(' ' + match.group('lineno') + ':' + match.group('command'), color=color)
7175
else:
7276
section = Section(match.group(1))
@@ -91,8 +95,11 @@ def load_logdata_from_url(url):
9195
try:
9296
urlhandle = urllib.request.urlopen(url)
9397
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)
98+
except urllib.error.HTTPError as e:
99+
print("HTTP error code %d reading URL %s: %s" % (e.code, url, e.reason), file=sys.stderr)
100+
sys.exit(1)
101+
except urllib.error.URLError as e:
102+
print("Error reading URL %s: %s" % (url, e.reason), file=sys.stderr)
96103
sys.exit(1)
97104

98105

@@ -187,7 +194,7 @@ def main():
187194
logdata = load_logdata_from_url(logpath)
188195
root = Tk()
189196
root.wm_title("osg-test log viewer: " + logpath)
190-
app = Application(root, logpath, logdata)
197+
Application(root, logpath, logdata)
191198
root.mainloop()
192199

193200
if __name__ == '__main__':

0 commit comments

Comments
 (0)