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