Revision 690,
1.3 KB
checked in by mattausch, 19 years ago
(diff) |
added ogre 1.07 main
|
Rev | Line | |
---|
[690] | 1 | import sys |
---|
| 2 | import os |
---|
| 3 | import getopt |
---|
| 4 | import string |
---|
| 5 | |
---|
| 6 | def fnParse( arg, dirname, files ): |
---|
| 7 | for file in files: |
---|
| 8 | for ext in arg: |
---|
| 9 | if file.rfind( ext, len(file)-len(ext), len(file) ) != -1 and not os.path.isdir( dirname + "/" + file ): |
---|
| 10 | fo = open( dirname + "/" + file, "rb" ) |
---|
| 11 | lines = fo.read() |
---|
| 12 | if not '\0' in lines and lines[len(lines)-1] != '\n': |
---|
| 13 | newlines = lines + '\n' |
---|
| 14 | fo.close() |
---|
| 15 | fo = open( dirname + "/" + file, "wb" ) |
---|
| 16 | fo.write(newlines) |
---|
| 17 | print "File " + dirname + "/" + file + " was changed." |
---|
| 18 | fo.close() |
---|
| 19 | |
---|
| 20 | def fnHelp(): |
---|
| 21 | helpstr = """ |
---|
| 22 | This nifty little program adds a CR/LF at the end of every |
---|
| 23 | file with the given extension within the directory tree |
---|
| 24 | from where it was called (i.e. recurses in sub-directories). |
---|
| 25 | |
---|
| 26 | Syntax: |
---|
| 27 | add_crlf [ext1] [ext2] [...] |
---|
| 28 | |
---|
| 29 | Extensions are given in the form: |
---|
| 30 | .cpp .h .txt (no asterisk at the beginning) |
---|
| 31 | |
---|
| 32 | Copyright (c) 2002 by Adrian Cearnau (cearny@cearny.ro) |
---|
| 33 | Any use, commercial or not, is allowed |
---|
| 34 | """ |
---|
| 35 | print helpstr |
---|
| 36 | |
---|
| 37 | if len(sys.argv) < 2: |
---|
| 38 | fnHelp() |
---|
| 39 | else: |
---|
| 40 | exts = sys.argv[1].split() |
---|
| 41 | currdir = os.getcwd() |
---|
| 42 | os.path.walk( currdir, fnParse, exts ) |
---|
| 43 | #print "\nTotally", num_files, "files were patched\n" |
---|
| 44 | print "done" |
---|
Note: See
TracBrowser
for help on using the repository browser.