X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fauxiliar%2Fstrip-whitespace.py;h=1d4a6e4ff378baa75e276c0276c4ec6d4969f5d4;hb=ca6e130e62a717b99db393f7262c9b34cb3d127d;hp=10da1162c568cf6808baad254fe082c861d1ce5c;hpb=c2a765855c4f125ba25bba6bcc2ae12c7a8807eb;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()