X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fauxiliar%2Fstrip-whitespace.py;h=1d4a6e4ff378baa75e276c0276c4ec6d4969f5d4;hb=2ce9d3b0ac456df77a73342fdf802f2e198c3b4e;hp=10da1162c568cf6808baad254fe082c861d1ce5c;hpb=37a1acdcb64020041d724e42e3e41b921e655709;p=lilypond.git diff --git a/scripts/auxiliar/strip-whitespace.py b/scripts/auxiliar/strip-whitespace.py index 10da1162c5..1d4a6e4ff3 100755 --- a/scripts/auxiliar/strip-whitespace.py +++ b/scripts/auxiliar/strip-whitespace.py @@ -1,16 +1,26 @@ #!/usr/bin/env python -import sys -for fname in sys.argv[1:]: - fd = open(fname,mode='U') # open in universal newline mode - lines = [] - for line in fd.readlines(): - lines.append( line.rstrip() ) - fd.close() +# This script removes trailing whitespace from files. +# It doesn't remove trailing newlines. +# As a side-effect, it converts line endings to Unix-style (LF). - fd = open(fname,mode='w') - fd.seek(0) - for line in lines: - fd.write(line+'\n') - fd.close() +import os, sys +# Iterate through all arguments. When the script is called +# with a wildcard (for example 'remove-trailing-whitespace.py *'), +# it's the *shell* that will expand the wildcard, and pass all +# resulting paths as arguments to the script. + +for pathname in sys.argv[1:]: + if os.path.isfile(pathname): + fd = open(pathname,mode='U') # open in universal newline mode + lines = [] + for line in fd.readlines(): + lines.append( line.rstrip() ) + fd.close() + + fd = open(pathname,mode='w') + fd.seek(0) + for line in lines: + fd.write(line+'\n') + fd.close()