MCPcopy Create free account
hub / github.com/catchorg/Catch2 / fixFile

Function fixFile

tools/scripts/fixWhitespace.py:21–45  ·  view source on GitHub ↗
( path )

Source from the content-addressed store, hash-verified

19 return changedFiles
20
21def fixFile( path ):
22 f = open( path, 'r' )
23 lines = []
24 changed = 0
25 for line in f:
26 trimmed = line.rstrip() + "\n"
27 trimmed = trimmed.replace('\t', ' ')
28 if trimmed != line:
29 changed = changed +1
30 lines.append( trimmed )
31 f.close()
32 if changed > 0:
33 global changedFiles
34 changedFiles = changedFiles + 1
35 print( path + ":" )
36 print( " - fixed " + str(changed) + " line(s)" )
37 altPath = path + ".backup"
38 os.rename( path, altPath )
39 f2 = open( path, 'w' )
40 for line in lines:
41 f2.write( line )
42 f2.close()
43 os.remove( altPath )
44 return True
45 return False
46
47changedFiles = fixAllFilesInDir(catchPath)
48if changedFiles > 0:

Callers 1

fixAllFilesInDirFunction · 0.85

Calls 3

printFunction · 0.85
closeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected