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