Blame SOURCES/pycparser-0.91.1-remove-relative-sys-path.py

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