Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

root/tags/cherrypy-2.1.0-rc1/tools/linefeed.py

Revision 109 (checked in by rboerma, 4 years ago)

changed \n --> \r\n for text files.

Line 
1 #! /usr/bin/env python
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()
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cpguest to create tickets