Last active
December 14, 2015 05:58
-
-
Save stevedoyle/5038893 to your computer and use it in GitHub Desktop.
Clean whitespace from source files. Remove trailing whitespace at the end of files and converts tabs to spaces.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
######################################################################### | |
# Script to clean up whitespace in source files. | |
# - Removes trailing whitespace at the end of lines | |
# - Converts tabs to spaces (4 spaces = 1 tab) | |
# | |
# Copyright 2013 Stephen Doyle | |
######################################################################### | |
import sys | |
import shutil | |
def cleanup(f): | |
# make a backup | |
shutil.copyfile(f, f+".bak") | |
lines = file(f, 'r').readlines() | |
outf = file(f, 'w') | |
for line in lines: | |
line = line.rstrip().replace("\t", " ") | |
print >>outf, line | |
if __name__ == "__main__": | |
files = sys.argv[1:] | |
for f in files: | |
cleanup(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment