diff options
author | Georg Brandl <georg@python.org> | 2009-03-28 19:33:33 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-03-28 19:33:33 (GMT) |
commit | 392775f615a53c22587178b453280f5a6441db2d (patch) | |
tree | 72b2cdc5f4e1c6454bcdab6285b41617d641020b /Tools/scripts | |
parent | b22b94886dc71ddc11c7dd748c2bb0a47113f5b8 (diff) | |
download | cpython-392775f615a53c22587178b453280f5a6441db2d.zip cpython-392775f615a53c22587178b453280f5a6441db2d.tar.gz cpython-392775f615a53c22587178b453280f5a6441db2d.tar.bz2 |
Add a script to fixup rst files if the pre-commit hook rejects them.
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-x | Tools/scripts/reindent-rst.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Tools/scripts/reindent-rst.py b/Tools/scripts/reindent-rst.py new file mode 100755 index 0000000..bf431d9 --- /dev/null +++ b/Tools/scripts/reindent-rst.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +# Make a reST file compliant to our pre-commit hook. +# Currently just remove trailing whitespace. + +from __future__ import with_statement +import sys, re, shutil + +ws_re = re.compile(r'\s+(\r?\n)$') + +def main(argv=sys.argv): + rv = 0 + for filename in argv[1:]: + try: + with open(filename, 'rb') as f: + lines = f.readlines() + new_lines = [ws_re.sub(r'\1', line) for line in lines] + if new_lines != lines: + print 'Fixing %s...' % filename + shutil.copyfile(filename, filename + '.bak') + with open(filename, 'wb') as f: + f.writelines(new_lines) + except Exception, err: + print 'Cannot fix %s: %s' % (filename, err) + rv = 1 + return rv + +if __name__ == '__main__': + sys.exit(main()) |