907710
#!/usr/bin/env python
907710
907710
'''
907710
pycparser examples all contain the following boiler plate code
907710
for running in tree. This script removes them:
907710
907710
# This is not required if you've installed pycparser into
907710
# your site-packages/ with setup.py
907710
#
907710
sys.path.extend(['.', '..'])
907710
'''
907710
907710
import sys
907710
import os
907710
907710
boiler_plate = "sys.path.extend(['.', '..'])\n"
907710
d = sys.argv[1]
907710
for (root, dirs, files) in os.walk(d):
907710
    for i in files:
907710
        if not i.endswith('.py'):
907710
            continue
907710
        fname = os.path.join(root, i)
907710
        lines = open(fname).readlines()
907710
        try:
907710
            start = lines.index(boiler_plate)
907710
            end = start
907710
        except ValueError:
907710
            start = None
907710
            end = start
907710
        if start is not None:
907710
            while lines[start-1].startswith('#'):
907710
                start -= 1
907710
907710
        if start is not None and end is not None:
907710
            f = open(fname, 'w')
907710
            f.writelines(lines[:start])
907710
            f.writelines(lines[end+1:])
907710
            f.close()