diff options
author | Scott Tsai <scottt.tw@gmail.com> | 2012-10-16 08:40:03 +0800 |
---|---|---|
committer | Scott Tsai <scottt.tw@gmail.com> | 2012-10-16 08:40:03 +0800 |
commit | 7bfcae70a2c96edd893c58760b2c0619e6c9d92e (patch) | |
tree | a78e22825d6ece21f806cf833fc59dc77a28e0e4 /remove-relative-sys-path | |
download | python-pycparser-7bfcae70a2c96edd893c58760b2c0619e6c9d92e.tar.gz python-pycparser-7bfcae70a2c96edd893c58760b2c0619e6c9d92e.tar.xz python-pycparser-7bfcae70a2c96edd893c58760b2c0619e6c9d92e.zip |
initial import
Diffstat (limited to 'remove-relative-sys-path')
-rwxr-xr-x | remove-relative-sys-path | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/remove-relative-sys-path b/remove-relative-sys-path new file mode 100755 index 0000000..20fcb06 --- /dev/null +++ b/remove-relative-sys-path @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +''' +pycparser examples all contain the following boiler plate code +for running in tree. This script removes them: + +# This is not required if you've installed pycparser into +# your site-packages/ with setup.py +# +sys.path.extend(['.', '..']) +''' + +import sys +import os + +boiler_plate = "sys.path.extend(['.', '..'])\n" +d = sys.argv[1] +for (root, dirs, files) in os.walk(d): + for i in files: + if not i.endswith('.py'): + continue + fname = os.path.join(root, i) + lines = open(fname).readlines() + try: + start = lines.index(boiler_plate) + end = start + except ValueError: + start = None + end = start + if start is not None: + while lines[start-1].startswith('#'): + start -= 1 + + if start is not None and end is not None: + f = open(fname, 'w') + f.writelines(lines[:start]) + f.writelines(lines[end+1:]) + f.close() |