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