#!/usr/bin/env python

import os
import re
import sys

rootdir = sys.argv[1]
pattern = 'print'
if len(sys.argv) >= 3:
    pattern = sys.argv[2]

ignore_pattern = (os.sep + '.svn' + os.sep)

regex = re.compile('^\s*%s' % pattern)
for root, dirs, files in os.walk(rootdir):
    for filename in files:
        fn = os.path.join(root, filename)
        if ignore_pattern in fn:
            continue
        for line in open(fn).readlines():
            if regex.search(line):
                print fn
                print '    ', line,


