diff options
author | Christian Heimes <christian@cheimes.de> | 2008-02-19 14:21:46 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-02-19 14:21:46 (GMT) |
commit | 7131fd957d9614b052ee6f7d367e51ae6da9a867 (patch) | |
tree | 798c25092a56b54fba9cf35b4981d721763de35c /Tools/scripts | |
parent | 5edc1c29eaa44bc48055c285b693a5bb728df002 (diff) | |
download | cpython-7131fd957d9614b052ee6f7d367e51ae6da9a867.zip cpython-7131fd957d9614b052ee6f7d367e51ae6da9a867.tar.gz cpython-7131fd957d9614b052ee6f7d367e51ae6da9a867.tar.bz2 |
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60878,60880-60892,60894-60898 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60876 | georg.brandl | 2008-02-17 16:14:10 +0100 (Sun, 17 Feb 2008) | 2 lines
Fix function name.
........
r60877 | facundo.batista | 2008-02-17 17:21:13 +0100 (Sun, 17 Feb 2008) | 4 lines
Now we handle different the backup copy, because of security
issues regarding user/group and permissions. Fixes 1050828.
........
r60878 | facundo.batista | 2008-02-17 19:59:29 +0100 (Sun, 17 Feb 2008) | 4 lines
Issue 2112. mmap does not raises EnvironmentError no more, but
a subclass of it. Thanks John Lenton.
........
r60882 | amaury.forgeotdarc | 2008-02-17 21:56:31 +0100 (Sun, 17 Feb 2008) | 5 lines
Compilation was broken on Windows since the introduction of Advanced String Formatting.
Only PCBuild (vs9) was really tested.
Changes for older compilers were done manually.
........
r60883 | georg.brandl | 2008-02-17 22:18:55 +0100 (Sun, 17 Feb 2008) | 2 lines
#2133: fix HTML color spec.
........
r60884 | facundo.batista | 2008-02-18 04:43:43 +0100 (Mon, 18 Feb 2008) | 5 lines
Issue #1916. Added isgenerator() and isgeneratorfunction() to
inspect.py. Thanks Javi Mansilla for patch review and
corrections.
........
r60885 | facundo.batista | 2008-02-18 13:48:43 +0100 (Mon, 18 Feb 2008) | 4 lines
Issue 1224. Now we support again the double slash in the URL.
Thanks Anthony Lenton.
........
r60887 | eric.smith | 2008-02-18 15:25:02 +0100 (Mon, 18 Feb 2008) | 1 line
Temporarily removed float tests. See issue 1600.
........
r60891 | kristjan.jonsson | 2008-02-18 18:40:47 +0100 (Mon, 18 Feb 2008) | 1 line
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
........
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-x | Tools/scripts/reindent.py | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/Tools/scripts/reindent.py b/Tools/scripts/reindent.py index 33ee4b7..11cb30a 100755 --- a/Tools/scripts/reindent.py +++ b/Tools/scripts/reindent.py @@ -4,10 +4,11 @@ """reindent [-d][-r][-v] [ path ... ] --d (--dryrun) Dry run. Analyze, but don't make any changes to, files. --r (--recurse) Recurse. Search for all .py files in subdirectories too. --v (--verbose) Verbose. Print informative msgs; else no output. --h (--help) Help. Print this usage information and exit. +-d (--dryrun) Dry run. Analyze, but don't make any changes to, files. +-r (--recurse) Recurse. Search for all .py files in subdirectories too. +-n (--nobackup) No backup. Does not make a ".bak" file before reindenting. +-v (--verbose) Verbose. Print informative msgs; else no output. +-h (--help) Help. Print this usage information and exit. Change Python (.py) files to use 4-space indents and no hard tab characters. Also trim excess spaces and tabs from ends of lines, and remove empty lines @@ -31,17 +32,23 @@ resulting .py file won't change it again). The hard part of reindenting is figuring out what to do with comment lines. So long as the input files get a clean bill of health from tabnanny.py, reindent should do a good job. + +The backup file is a copy of the one that is being reindented. The ".bak" +file is generated with shutil.copy(), but some corner cases regarding +user/group and permissions could leave the backup file more readable that +you'd prefer. You can always use the --nobackup option to prevent this. """ __version__ = "1" import tokenize -import os +import os, shutil import sys -verbose = 0 -recurse = 0 -dryrun = 0 +verbose = 0 +recurse = 0 +dryrun = 0 +makebackup = True def usage(msg=None): if msg is not None: @@ -57,10 +64,10 @@ def errprint(*args): def main(): import getopt - global verbose, recurse, dryrun + global verbose, recurse, dryrun, makebackup try: - opts, args = getopt.getopt(sys.argv[1:], "drvh", - ["dryrun", "recurse", "verbose", "help"]) + opts, args = getopt.getopt(sys.argv[1:], "drnvh", + ["dryrun", "recurse", "nobackup", "verbose", "help"]) except getopt.error as msg: usage(msg) return @@ -69,6 +76,8 @@ def main(): dryrun += 1 elif o in ('-r', '--recurse'): recurse += 1 + elif o in ('-n', '--nobackup'): + makebackup = False elif o in ('-v', '--verbose'): verbose += 1 elif o in ('-h', '--help'): @@ -112,11 +121,10 @@ def check(file): print("But this is a dry run, so leaving it alone.") if not dryrun: bak = file + ".bak" - if os.path.exists(bak): - os.remove(bak) - os.rename(file, bak) - if verbose: - print("renamed", file, "to", bak) + if makebackup: + shutil.copyfile(file, bak) + if verbose: + print("backed up", file, "to", bak) f = open(file, "w") r.write(f) f.close() |