incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1470177 - /incubator/public/trunk/voter/voter.py
Date Sat, 20 Apr 2013 15:31:09 GMT
Author: brane
Date: Sat Apr 20 15:31:08 2013
New Revision: 1470177

URL: http://svn.apache.org/r1470177
Log:
Voter: learn to prune revealing paths from error messages.

Modified:
    incubator/public/trunk/voter/voter.py

Modified: incubator/public/trunk/voter/voter.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/voter/voter.py?rev=1470177&r1=1470176&r2=1470177&view=diff
==============================================================================
--- incubator/public/trunk/voter/voter.py (original)
+++ incubator/public/trunk/voter/voter.py Sat Apr 20 15:31:08 2013
@@ -36,6 +36,7 @@ Status: Alpha
 from __future__ import absolute_import
 
 import os, re, sys
+import argparse
 import collections
 import datetime
 import email
@@ -277,10 +278,14 @@ class VoteDatabase(object):
         con.close()
 
 
-    def __init__(self, path):
+    def __init__(self, path, prune_error_message=None):
         assert os.path.isfile(path)
         self.con = self.__connect(path)
         self.__updated = None
+        if not prune_error_message:
+            self.__prune_error_message = lambda message: message
+        else:
+            self.__prune_error_message = prune_error_message
 
     class __Transaction(object):
         __slots__ = ['__db']
@@ -412,10 +417,10 @@ class VoteDatabase(object):
             cursor.execute("DELETE FROM issue");
             if not issues:
                 return
-            for issue in issues:
+            for kind, message in issues:
                 cursor.execute("INSERT INTO issue (kind, message)"
                                " VALUES (?, ?)",
-                               issue)
+                               (kind, self.__prune_error_message(message)))
 
     def __list_votes(self, active):
         if active:
@@ -463,11 +468,34 @@ class VoteDatabase(object):
 
 
 def main():
+    parser = argparse.ArgumentParser(
+        description = 'Generate Incubator voting status page.')
+    parser.add_argument('mbox_archive', metavar = 'mbox-archive',
+                        help = 'Path to the mailing list archives')
+    parser.add_argument('--prune', dest='prune', action='store', default=None,
+                        help='Pattern to prune from error messages (regex)')
+    args = parser.parse_args()
+
     votes_path = SiteStructure.votes_database()
     if not os.path.isfile(votes_path):
         VoteDatabase.create(votes_path)
-    updater = VoteUpdater(sys.argv[1])
-    database = VoteDatabase(votes_path)
+
+    archive_rx = re.compile(re.escape(args.mbox_archive))
+    if args.prune:
+        prune_rx = re.compile(args.prune)
+    else:
+        prune_rx = None
+
+    def prune_error_message(message):
+        match = archive_rx.search(message)
+        if match:
+            message = message[:match.start()] + '...' + message[match.end():]
+        match = (prune_rx and prune_rx.search(message))
+        if match:
+            message = message[:match.start()] + '...' + message[match.end():]
+
+    updater = VoteUpdater(args.mbox_archive)
+    database = VoteDatabase(votes_path, prune_error_message)
     updater.record(database)
     database.prune_old_votes()
     database.close()



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message