forked from OGRECave/ogre
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrem_endspc.py
60 lines (51 loc) · 1.84 KB
/
rem_endspc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/env python
import sys
import os
import getopt
import string
import re
def fnParse( arg, dirname, files ):
for file in files:
for ext in arg:
if file.rfind( ext, len(file)-len(ext), len(file) ) != -1 and not os.path.isdir( dirname + "/" + file ):
print "Parsing file " + dirname + "/" + file + "..."
fo = open( dirname + "/" + file, "r" )
lines = fo.readlines()
fo.close()
fo = open( dirname + "/" + file, "r" )
newlines = fo.readlines()
changed = 0
for i in range(0, len(newlines) - 1):
newlines[i] = re.sub( "[ \t]+$", "", newlines[i] )
changed = 1
if changed == 1:
backup = open( dirname + "/" + file + "~", "w" )
backup.writelines( lines )
backup.close()
fo.close()
fo = open( dirname + "/" + file, "w" )
fo.writelines( newlines )
print "File " + dirname + "/" + file + " was changed."
fo.close()
def fnHelp():
helpstr = """
This program deletes all the 'dangling' spaces at the end
of all the lines in all the files with the passed extensions
within the directory tree from whose root it was called
(i.e. recurses into sub-directories)
Syntax:
rem_endspc [ext1] [ext2] [...]
Extensions are given in the form:
.cpp .h .txt (no asterisk at the beginning)
Copyright (c) 2002 by Adrian Cearnau (cearny@cearny.ro)
Any use, commercial or not, is allowed
"""
print helpstr
if len(sys.argv) < 2:
fnHelp()
else:
exts = sys.argv[1].split()
currdir = os.getcwd()
os.path.walk( currdir, fnParse, exts )
#print "\nTotally", num_files, "files were patched\n"
print "done"