[pypy-svn] rev 1558 - pypy/trunk/src/pypy/tool
dinu at codespeak.net
dinu at codespeak.net
Fri Oct 3 19:44:23 CEST 2003
Author: dinu
Date: Fri Oct 3 19:44:23 2003
New Revision: 1558
Modified:
pypy/trunk/src/pypy/tool/fixeol
Log:
Added doc strings
Modified: pypy/trunk/src/pypy/tool/fixeol
==============================================================================
--- pypy/trunk/src/pypy/tool/fixeol (original)
+++ pypy/trunk/src/pypy/tool/fixeol Fri Oct 3 19:44:23 2003
@@ -1,18 +1,23 @@
#! /usr/bin/env python
+
import sys, os
+
forbidden = range(0,32)
forbidden.remove(9) # tab
forbidden.remove(10) # lf
forbidden.remove(12) # ^L
forbidden.remove(13) # cr
+
def looksbinary(data, forbidden = [chr(i) for i in forbidden]):
+ "Check if some data chunk appears to be binary."
for c in forbidden:
if c in data:
return True
return False
+
# hack to get the platform's native end-of-line format
f = open('@fixeol at tmp.txt', 'w')
print >> f
@@ -22,8 +27,9 @@
f.close()
os.unlink('@fixeol at tmp.txt')
+
def binary2text(filename, native_eol = native_eol):
- # convert to the platform's native end-of-line format if needed
+ "Convert a file to the platform's native end-of-line format if needed."
f = open(filename, 'rb')
data = f.read()
f.close()
@@ -39,7 +45,9 @@
f.close()
return True
+
def asserttextfile(fname):
+ "Assert a file is a text file or issue a warning otherwise."
# safety check to nail binary files
if not binary2text(fname):
print >> sys.stderr, "*** warning, looks like a binary file:",
@@ -50,6 +58,7 @@
def fixpyfiles(ignored, dirname, fnames):
+ "Fix Python files in some directory."
numpyfiles = 0
for fname in fnames:
if fname.endswith('.py') or fname.endswith('.txt') or fname.endswith('.asc'):
@@ -70,6 +79,7 @@
if '.svn' in fnames:
fnames.remove('.svn')
+
if __name__ == '__main__':
if len(sys.argv) > 1:
for fname in sys.argv[1:]:
More information about the Pypy-commit
mailing list