summaryrefslogtreecommitdiff
path: root/app-admin/syslog-summary/files/syslog-summary-1.14-py3.patch
blob: 945c7ce290bee1e31d2ba43b9bb80d0991c632b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
diff --git a/syslog-summary b/syslog-summary
index abf6381..a658c14 100755
--- a/syslog-summary
+++ b/syslog-summary
@@ -35,6 +35,8 @@ Lars Wirzenius <liw@iki.fi>
 Tommi Virtanen <tv@debian.org>
 David Paleino <d.paleino@gmail.com>"""
 
+from __future__ import print_function
+
 version = "1.14"
 
 import sys, re, getopt, string
@@ -62,7 +64,7 @@ def io_error(err, filename, die=True):
 		if die:
 			traceback.print_exc(file=sys.stderr)
 		else:
-			print "[E] %s [%s(%s) - %s]" % (os.strerror(num), errno.errorcode[num], num, filename)
+			print("[E] %s [%s(%s) - %s]" % (os.strerror(num), errno.errorcode[num], num, filename))
 
 	if die:
 		sys.exit(1)
@@ -72,7 +74,7 @@ def read_patterns(filename):
 	pats = []
 	try:
 		f = open(filename, "r")
-	except IOError, e:
+	except IOError as e:
 		io_error(e, filename, False)
 		return []
 	for line in f:
@@ -91,7 +93,7 @@ def read_states(filename):
 		return states
 	try:
 		f = open(filename, "r")
-	except IOError, e:
+	except IOError as e:
 		io_error(e, filename, False)
 		return states
 	for line in f:
@@ -105,9 +107,9 @@ def save_states(filename, states):
 		return
 	try:
 		f = open(filename, "w")
-	except IOError, e:
+	except IOError as e:
 		io_error(e, filename, True)
-	for filename in states.keys():
+	for filename in list(states.keys()):
 		value = states[filename]
 		f.write("%s %d %s\n" % (filename, value[0], value[1]))
 	f.close()
@@ -123,7 +125,7 @@ def split_date(line):
 		m = pat.match(line)
 		if m:
 			return line[:m.end()], line[m.end():]
-	print "line has bad date", "<" + string.rstrip(line) + ">"
+	print("line has bad date", "<" + string.rstrip(line) + ">")
 	return None, line
 
 def is_gzipped(filename):
@@ -152,7 +154,7 @@ def summarize(filename, states):
 	order = []
 	ignored_count = 0
 	if not QUIET:
-		print "Summarizing %s" % filename
+		print("Summarizing %s" % filename)
 	
 	# If the file is a gzipped log, open it
 	# using the proper function from the gzip
@@ -162,7 +164,7 @@ def summarize(filename, states):
 			file = gzopen(filename, "rb")
 		else:
 			file = open(filename, "r")
-	except IOError, e:
+	except IOError as e:
 		io_error(e, filename, True)
 		
 	linecount = 0
@@ -170,7 +172,7 @@ def summarize(filename, states):
 	shaobj = sha1()
 	if filename in states:
 		oldlines, oldsha = states[filename]
-		for i in xrange(oldlines):
+		for i in range(oldlines):
 			line = file.readline()
 			shaobj.update(line)
 #		print "OLD-new: %s" % shaobj.hexdigest()
@@ -182,7 +184,7 @@ def summarize(filename, states):
 		else:
 			linecount = oldlines
 	if not QUIET:
-		print "%8d Lines skipped (already processed)" % linecount
+		print("%8d Lines skipped (already processed)" % linecount)
 
 	line = file.readline()
 	previous = None
@@ -190,13 +192,13 @@ def summarize(filename, states):
 	foo=0
 	while line:
 #		foo+=1
-		shaobj.update(line)
+		shaobj.update(line.encode())
 		linecount += 1
 		
 		if should_be_ignored(line):
 			ignored_count += 1
 			if DEBUG:
-				print "Ignoring: %s" % line
+				print("Ignoring: %s" % line)
 			line = file.readline()
 		
 		date, rest = split_date(line)
@@ -213,7 +215,7 @@ def summarize(filename, states):
 			count = int(repeated.group(1))
 			rest = previous
 
-		if counts.has_key(rest):
+		if rest in counts:
 			counts[rest] = counts[rest] + count
 		else:
 			assert count == 1
@@ -233,14 +235,14 @@ def summarize(filename, states):
 #	print states
 	
 	if QUIET and order:
-		print "Summarizing %s" % filename
+		print("Summarizing %s" % filename)
 	if not QUIET or order:
-		print "%8d Patterns to ignore" % len(ignore_pats)
-		print "%8d Ignored lines" % ignored_count
+		print("%8d Patterns to ignore" % len(ignore_pats))
+		print("%8d Ignored lines" % ignored_count)
 	for rest in order:
-		print "%8d %s" % (counts[rest], rest),
+		print("%8d %s" % (counts[rest], rest), end='')
 	if not QUIET or order:
-		print
+		print()
 
 def main():
 	global ignore_pats, IGNORE_FILENAME, STATE_FILENAME, REPEAT, QUIET, DEBUG