--- a/fixbot/logwatch/message.py Fri Feb 05 22:20:59 2010 +0200
+++ b/fixbot/logwatch/message.py Fri Feb 05 22:56:14 2010 +0200
@@ -6,6 +6,7 @@
import syslog
import time, datetime
import re
+import os.path
PRIORITY_NAMES = {
syslog.LOG_EMERG: 'emerg',
@@ -177,6 +178,42 @@
message = self.message,
)
+ @property
+ def normalized_program (self) :
+ """
+ Returns a normalized version of the program name:
+ - lowercase
+ - no path components
+
+ Returns None if there is no program tag
+ """
+
+ if self.program is None :
+ return None
+
+ else :
+ return os.path.basename(self.program).lower()
+
+ def match_program (self, program) :
+ """
+ If the given value is False, checks that this message does *not* have a program tag.
+
+ Otherwise, does a case-insensitive basename() compare of the given value against the message tag's program
+ name portion.
+ """
+
+ if program is False :
+ # only match if no tag
+ return self.program is None
+
+ elif self.program is None :
+ # no program to match against...
+ return False
+
+ else :
+ # match against normalized name
+ return self.normalized_program == program.lower()
+
def match (self, regexp=None, program=None) :
"""
Evaluate a match against this message using the given criteria
@@ -187,21 +224,11 @@
params = {}
- ## program
- if program is False :
- # only match if no tag
- if self.program is not None :
+ if program is not None :
+ if not self.match_program(program) :
+ # program did not match
return False
- elif program is not None :
- # case-insensitive match
- if self.program.lower() != program.lower() :
- return False
-
- else :
- # params
- params['program'] = self.program
-
## pattern
if regexp is not None :
# apply regexp