|
Revision 109
(checked in by rboerma, 4 years ago)
|
changed \n --> \r\n for text files.
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
"Replace CRLF with LF cherrypy files. Print names of changed files." |
|---|
| 3 |
|
|---|
| 4 |
import sys, os |
|---|
| 5 |
import glob, os.path |
|---|
| 6 |
import re |
|---|
| 7 |
|
|---|
| 8 |
def main(): |
|---|
| 9 |
scriptdir = os.path.split(sys.argv[0])[0] |
|---|
| 10 |
basepath = os.path.split(scriptdir)[0] |
|---|
| 11 |
filelist = [] |
|---|
| 12 |
for directory in ['/tools','/cherrypy','/cherrypy/lib/filter','/', |
|---|
| 13 |
'/cherrypy/lib','/cherrypy/test','/cherrypy/tutorial']: |
|---|
| 14 |
filelist.extend(glob.glob(basepath+directory+'/*.py')) |
|---|
| 15 |
filelist.extend(glob.glob(basepath+directory+'/*.conf')) |
|---|
| 16 |
filelist.extend(glob.glob(basepath+directory+'/*.txt')) |
|---|
| 17 |
for filename in filelist: |
|---|
| 18 |
if os.path.isdir(filename): |
|---|
| 19 |
print filename, "Directory!" |
|---|
| 20 |
continue |
|---|
| 21 |
data = open(filename, "rb").read() |
|---|
| 22 |
if '\0' in data: |
|---|
| 23 |
print filename, "Binary!" |
|---|
| 24 |
continue |
|---|
| 25 |
if os.path.splitext(filename)[1].lower() == '.txt': |
|---|
| 26 |
newdata = data.replace('\n','\r\n') |
|---|
| 27 |
else: |
|---|
| 28 |
newdata = data.replace('\r\n','\n') |
|---|
| 29 |
if newdata != data: |
|---|
| 30 |
print filename |
|---|
| 31 |
f = open(filename, "wb") |
|---|
| 32 |
f.write(newdata) |
|---|
| 33 |
f.close() |
|---|
| 34 |
|
|---|
| 35 |
if __name__ == '__main__': |
|---|
| 36 |
main() |
|---|