annotate Tools/scripts/mailerdaemon.py @ 9281:809dcc1bbc21 legacy-trunk

Added #! line
author Guido van Rossum <guido@python.org>
date Wed, 07 Oct 1998 14:46:09 +0000
parents 7a9afaba88d8
children f33b394e5d7f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
1 """mailerdaemon - classes to parse mailer-daemon messages"""
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
2
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
3 import string
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
4 import rfc822
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
5 import calendar
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
6 import regex
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
7 import os
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
8 import sys
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
9
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
10 Unparseable = 'mailerdaemon.Unparseable'
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
11
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
12 class ErrorMessage(rfc822.Message):
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
13 def __init__(self, fp):
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
14 rfc822.Message.__init__(self, fp)
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
15
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
16 def is_warning(self):
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
17 sub = self.getheader('Subject')
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
18 if not sub:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
19 return 0
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
20 sub = string.lower(sub)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
21 if sub[:12] == 'waiting mail': return 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
22 if string.find(sub, 'warning') >= 0: return 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
23 self.sub = sub
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
24 return 0
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
25
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
26 def get_errors(self):
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
27 for p in EMPARSERS:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
28 self.rewindbody()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
29 try:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
30 return p(self.fp, self.sub)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
31 except Unparseable:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
32 pass
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
33 raise Unparseable
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
34
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
35 sendmail_pattern = regex.compile('[0-9][0-9][0-9] ')
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
36 def emparse_sendmail(fp, sub):
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
37 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
38 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
39 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
40 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
41 line = line[:-1]
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
42
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
43 # Check that we're not in the returned message yet
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
44 if string.lower(line)[:5] == 'from:':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
45 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
46 line = string.split(line)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
47 if len(line) > 3 and \
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
48 ((line[0] == '-----' and line[1] == 'Transcript') or
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
49 (line[0] == '---' and line[1] == 'The' and
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
50 line[2] == 'transcript') or
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
51 (line[0] == 'While' and
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
52 line[1] == 'talking' and
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
53 line[2] == 'to')):
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
54 # Yes, found it!
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
55 break
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
56
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
57 errors = []
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
58 found_a_line = 0
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
59 warnings = 0
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
60 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
61 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
62 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
63 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
64 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
65 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
66 continue
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
67 if sendmail_pattern.match(line) == 4:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
68 # Yes, an error/warning line. Ignore 4, remember 5, stop on rest
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
69 if line[0] == '5':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
70 errors.append(line)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
71 elif line[0] == '4':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
72 warnings = 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
73 else:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
74 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
75 line = string.split(line)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
76 if line and line[0][:3] == '---':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
77 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
78 found_a_line = 1
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
79 # special case for CWI sendmail
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
80 if len(line) > 1 and line[1] == 'Undelivered':
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
81 while 1:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
82 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
83 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
84 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
85 line = string.strip(line)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
86 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
87 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
88 errors.append(line + ': ' + sub)
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
89 # Empty transcripts are ok, others without an error are not.
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
90 if found_a_line and not (errors or warnings):
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
91 raise Unparseable
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
92 return errors
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
93
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
94 def emparse_cts(fp, sub):
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
95 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
96 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
97 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
98 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
99 line = line[:-1]
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
100
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
101 # Check that we're not in the returned message yet
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
102 if string.lower(line)[:5] == 'from:':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
103 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
104 line = string.split(line)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
105 if len(line) > 3 and line[0][:2] == '|-' and line[1] == 'Failed' \
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
106 and line[2] == 'addresses':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
107 # Yes, found it!
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
108 break
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
109
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
110 errors = []
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
111 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
112 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
113 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
114 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
115 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
116 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
117 continue
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
118 if line[:2] == '|-':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
119 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
120 errors.append(line)
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
121 return errors
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
122
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
123 def emparse_aol(fp, sub):
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
124 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
125 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
126 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
127 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
128 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
129 if line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
130 break
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
131 exp = 'The mail you sent could not be delivered to:'
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
132 if line[:len(exp)] != exp:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
133 raise Unparseable
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
134 errors = []
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
135 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
136 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
137 if sendmail_pattern.match(line) == 4:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
138 # Yes, an error/warning line. Ignore 4, remember 5, stop on rest
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
139 if line[0] == '5':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
140 errors.append(line)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
141 elif line[0] != '4':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
142 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
143 elif line == '\n':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
144 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
145 else:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
146 raise Unparseable
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
147 return errors
3238
d3510f1118b6 Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents: 3222
diff changeset
148
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
149 def emparse_compuserve(fp, sub):
3238
d3510f1118b6 Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents: 3222
diff changeset
150 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
151 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
152 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
153 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
154 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
155 if line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
156 break
3238
d3510f1118b6 Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents: 3222
diff changeset
157 exp = 'Your message could not be delivered for the following reason:'
d3510f1118b6 Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents: 3222
diff changeset
158 if line[:len(exp)] != exp:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
159 raise Unparseable
3238
d3510f1118b6 Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents: 3222
diff changeset
160 errors = []
d3510f1118b6 Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents: 3222
diff changeset
161 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
162 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
163 if not line: break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
164 if line[:3] == '---': break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
165 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
166 if not line: continue
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
167 if line == 'Please resend your message at a later time.':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
168 continue
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
169 line = 'Compuserve: ' + line
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
170 errors.append(line)
3238
d3510f1118b6 Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents: 3222
diff changeset
171 return errors
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
172
3239
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
173 prov_pattern = regex.compile('.* | \(.*\)')
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
174 def emparse_providence(fp, sub):
3239
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
175 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
176 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
177 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
178 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
179 line = line[:-1]
3239
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
180
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
181 # Check that we're not in the returned message yet
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
182 if string.lower(line)[:5] == 'from:':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
183 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
184 exp = 'The following errors occurred'
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
185 if line[:len(exp)] == exp:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
186 break
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
187
3239
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
188 errors = []
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
189 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
190 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
191 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
192 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
193 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
194 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
195 continue
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
196 if line[:4] == '----':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
197 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
198 if prov_pattern.match(line) > 0:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
199 errors.append(prov_pattern.group(1))
3239
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
200
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
201 if not errors:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
202 raise Unparseable
3239
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
203 return errors
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
204
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
205 def emparse_x400(fp, sub):
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
206 exp = 'This report relates to your message:'
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
207 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
208 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
209 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
210 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
211 line = line[:-1]
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
212
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
213 # Check that we're not in the returned message yet
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
214 if string.lower(line)[:5] == 'from:':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
215 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
216 if line[:len(exp)] == exp:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
217 break
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
218
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
219 errors = []
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
220 exp = 'Your message was not delivered to'
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
221 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
222 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
223 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
224 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
225 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
226 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
227 continue
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
228 if line[:len(exp)] == exp:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
229 error = string.strip(line[len(exp):])
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
230 sep = ': '
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
231 while 1:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
232 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
233 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
234 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
235 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
236 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
237 break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
238 if line[0] == ' ' and line[-1] != ':':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
239 error = error + sep + string.strip(line)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
240 sep = '; '
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
241 errors.append(error)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
242 return errors
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
243 raise Unparseable
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
244
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
245 def emparse_passau(fp, sub):
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
246 exp = 'Unable to deliver message because'
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
247 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
248 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
249 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
250 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
251 if string.lower(line)[:5] == 'from:':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
252 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
253 if line[:len(exp)] == exp:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
254 break
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
255
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
256 errors = []
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
257 exp = 'Returned Text follows'
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
258 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
259 line = fp.readline()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
260 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
261 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
262 line = line[:-1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
263 # Check that we're not in the returned message yet
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
264 if string.lower(line)[:5] == 'from:':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
265 raise Unparseable
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
266 if not line:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
267 continue
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
268 if line[:len(exp)] == exp:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
269 return errors
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
270 errors.append(string.strip(line))
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
271
3239
285dba4e0e51 Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents: 3238
diff changeset
272 EMPARSERS = [emparse_sendmail, emparse_aol, emparse_cts, emparse_compuserve,
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
273 emparse_providence, emparse_x400, emparse_passau]
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
274
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
275 def sort_numeric(a, b):
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
276 a = string.atoi(a)
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
277 b = string.atoi(b)
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
278 if a < b: return -1
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
279 elif a > b: return 1
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
280 else: return 0
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
281
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
282 def parsedir(dir, modify):
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
283 os.chdir(dir)
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
284 pat = regex.compile('^[0-9]*$')
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
285 errordict = {}
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
286 errorfirst = {}
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
287 errorlast = {}
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
288 nok = nwarn = nbad = 0
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
289
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
290 # find all numeric file names and sort them
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
291 files = filter(lambda fn, pat=pat: pat.match(fn) > 0, os.listdir('.'))
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
292 files.sort(sort_numeric)
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
293
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
294 for fn in files:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
295 # Lets try to parse the file.
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
296 fp = open(fn)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
297 m = ErrorMessage(fp)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
298 sender = m.getaddr('From')
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
299 print '%s\t%-40s\t'%(fn, sender[1]),
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
300
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
301 if m.is_warning():
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
302 print 'warning only'
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
303 nwarn = nwarn + 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
304 if modify:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
305 os.unlink(fn)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
306 continue
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
307
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
308 try:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
309 errors = m.get_errors()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
310 except Unparseable:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
311 print '** Not parseable'
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
312 nbad = nbad + 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
313 continue
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
314 print len(errors), 'errors'
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
315
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
316 # Remember them
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
317 for e in errors:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
318 try:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
319 mm, dd = m.getdate('date')[1:1+2]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
320 date = '%s %02d' % (calendar.month_abbr[mm], dd)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
321 except:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
322 date = '??????'
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
323 if not errordict.has_key(e):
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
324 errordict[e] = 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
325 errorfirst[e] = '%s (%s)' % (fn, date)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
326 else:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
327 errordict[e] = errordict[e] + 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
328 errorlast[e] = '%s (%s)' % (fn, date)
3780
ac114a5fc8ff More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents: 3251
diff changeset
329
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
330 nok = nok + 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
331 if modify:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
332 os.unlink(fn)
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
333
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
334 print '--------------'
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
335 print nok, 'files parsed,',nwarn,'files warning-only,',
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
336 print nbad,'files unparseable'
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
337 print '--------------'
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
338 for e in errordict.keys():
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
339 print errordict[e], errorfirst[e], '-', errorlast[e], '\t', e
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
340
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
341 def main():
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
342 modify = 0
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
343 if len(sys.argv) > 1 and sys.argv[1] == '-d':
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
344 modify = 1
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
345 del sys.argv[1]
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
346 if len(sys.argv) > 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
347 for folder in sys.argv[1:]:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
348 parsedir(folder, modify)
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
349 else:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 3780
diff changeset
350 parsedir('/ufs/jack/Mail/errorsinbox', modify)
3222
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
351
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
352 if __name__ == '__main__' or sys.argv[0] == __name__:
0f38cec56539 Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
353 main()