Mercurial > cpython-lru_cache-weakref
view Tools/scripts/untabify.py @ 58689:514b56efd89a 3.1
Merged revisions 77962 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines
Merged revisions 77943,77959-77960 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines
Explicitly mention the default value for formatdate's usegmt parameter.
........
r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line
Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert
........
r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines
Add Chris Rebert to ACKS for issue 6760 Popen doc improvements.
........
................
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 04 Feb 2010 16:44:31 +0000 |
| parents | e4ade16a694f |
| children | 05ee6f8c0260 fcfe324663a6 |
line wrap: on
line source
#! /usr/bin/env python "Replace tabs with spaces in argument files. Print names of changed files." import os import sys import getopt def main(): tabsize = 8 try: opts, args = getopt.getopt(sys.argv[1:], "t:") if not args: raise getopt.error("At least one file argument required") except getopt.error as msg: print(msg) print("usage:", sys.argv[0], "[-t tabwidth] file ...") return for optname, optvalue in opts: if optname == '-t': tabsize = int(optvalue) for filename in args: process(filename, tabsize) def process(filename, tabsize): try: f = open(filename) text = f.read() f.close() except IOError as msg: print("%r: I/O error: %s" % (filename, msg)) return newtext = text.expandtabs(tabsize) if newtext == text: return backup = filename + "~" try: os.unlink(backup) except os.error: pass try: os.rename(filename, backup) except os.error: pass f = open(filename, "w") f.write(newtext) f.close() print(filename) if __name__ == '__main__': main()
