Skip to content

Commit dd17897

Browse files
committed
cmd line option to ignore authors matching the given reg ex. Useful if
there are scripts that do checkins.
1 parent 802f3da commit dd17897

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

bin/convert_logs.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from xml.sax.saxutils import escape as h
99
from sys import stderr
1010
import re
11+
import sre_constants
1112

1213
# Some global variables
1314
SVN_SEP = "------------------------------------------------------------------------"
@@ -70,6 +71,15 @@ def main(argv):
7071
else:
7172
print >>stderr, "No repository format given, for more info see:\n convert_logs.py help"
7273
sys.exit(1)
74+
75+
# check for valid cmd line arguments before doing anything
76+
if opts.ignore_author is not None:
77+
try:
78+
re.compile(opts.ignore_author)
79+
except sre_constants.error:
80+
print >>stderr, "Unable to compile author reg ex: %s" % \
81+
opts.ignore_author
82+
sys.exit(1)
7383

7484
if not os.path.exists(log_file):
7585
#hacky, but OptionParse doesn't support options that only sometimes
@@ -82,8 +92,12 @@ def main(argv):
8292
else:
8393
log_file = open(log_file, 'r')
8494

85-
events = parser(log_file, opts)
86-
95+
events = parser(log_file, opts)
96+
97+
# Remove all authors we wanted to ignore here
98+
if opts.ignore_author is not None:
99+
events = remove_ignored_author(opts.ignore_author, events)
100+
87101
#its really best if we don't have to sort, but by default most are
88102
# in the reverse order that we want, so we sort by default
89103
if not opts.nosort:
@@ -159,6 +173,10 @@ def parse_args(argv):
159173
p.add_option("--nosort", dest="nosort", default=False, action="store_true",
160174
help="use if the input log is already in chronological order for speed")
161175

176+
p.add_option("--ignore-author", dest="ignore_author", default=None,
177+
action="store",
178+
help="Ignore authors that match this regular expression.")
179+
162180

163181
(options, args) = p.parse_args(argv)
164182

@@ -397,6 +415,14 @@ def parse_perforce_path(file_handle, opts):
397415
if file_key_re.match(key_name):
398416
yield Event(file_name, int(changelist['time'] + '000'), changelist['user'])
399417

418+
419+
def remove_ignored_author(ignore, events):
420+
""" Remove the events that match the given ignore reg ex. """
421+
events = filter(lambda evt: re.match(ignore, evt.author) is None,
422+
events)
423+
return events
424+
425+
400426
def run_marshal(command):
401427
import marshal
402428

0 commit comments

Comments
 (0)