aboutsummaryrefslogtreecommitdiff
path: root/unittest/Catch/scripts/fixTrailingWhitespace.py
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:53:56 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:53:56 +0100
commite9fc58cb304323f07aba736fc523903481404cff (patch)
tree59db450412ca101aa9601b3f2174436898f955c1 /unittest/Catch/scripts/fixTrailingWhitespace.py
parent8150ee4edc7e32d5c27cd3e0f68c630d90865638 (diff)
parent48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391 (diff)
downloadlibnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.gz
libnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.bz2
Merge commit '48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391' as 'unittest/Catch'
Diffstat (limited to 'unittest/Catch/scripts/fixTrailingWhitespace.py')
-rw-r--r--unittest/Catch/scripts/fixTrailingWhitespace.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/unittest/Catch/scripts/fixTrailingWhitespace.py b/unittest/Catch/scripts/fixTrailingWhitespace.py
new file mode 100644
index 0000000..a1b6bbe
--- /dev/null
+++ b/unittest/Catch/scripts/fixTrailingWhitespace.py
@@ -0,0 +1,46 @@
+from __future__ import print_function
+import os
+from scriptCommon import catchPath
+
+changedFiles = 0
+
+def isSourceFile( path ):
+ return path.endswith( ".cpp" ) or path.endswith( ".h" ) or path.endswith( ".hpp" )
+
+def fixAllFilesInDir( dir ):
+ for f in os.listdir( dir ):
+ path = os.path.join( dir,f )
+ if os.path.isfile( path ):
+ if isSourceFile( path ):
+ fixFile( path )
+ else:
+ fixAllFilesInDir( path )
+
+def fixFile( path ):
+ f = open( path, 'r' )
+ lines = []
+ changed = 0
+ for line in f:
+ trimmed = line.rstrip() + "\n"
+ if trimmed != line:
+ changed = changed +1
+ lines.append( trimmed )
+ f.close()
+ if changed > 0:
+ global changedFiles
+ changedFiles = changedFiles + 1
+ print( path + ":" )
+ print( " - fixed " + str(changed) + " line(s)" )
+ altPath = path + ".backup"
+ os.rename( path, altPath )
+ f2 = open( path, 'w' )
+ for line in lines:
+ f2.write( line )
+ f2.close()
+ os.remove( altPath )
+
+fixAllFilesInDir(catchPath)
+if changedFiles > 0:
+ print( "Fixed " + str(changedFiles) + " file(s)" )
+else:
+ print( "No trailing whitespace found" )