/
usr
/
lib64
/
python2.6
/
Tools
/
scripts
/
/usr/lib64/python2.6/Tools/scripts
mkdir
upload
Name
Size
Mode
Actions
byext.py
3919
0755
edit
dl
rm
byext.pyc
4465
0644
edit
dl
rm
byext.pyo
4465
0644
edit
dl
rm
byteyears.py
1641
0755
edit
dl
rm
byteyears.pyc
1416
0644
edit
dl
rm
byteyears.pyo
1416
0644
edit
dl
rm
checkappend.py
4661
0755
edit
dl
rm
checkappend.pyc
4952
0644
edit
dl
rm
checkappend.pyo
4952
0644
edit
dl
rm
checkpyc.py
2014
0755
edit
dl
rm
checkpyc.pyc
2011
0644
edit
dl
rm
checkpyc.pyo
2011
0644
edit
dl
rm
classfix.py
5956
0755
edit
dl
rm
classfix.pyc
4254
0644
edit
dl
rm
classfix.pyo
4254
0644
edit
dl
rm
cleanfuture.py
8581
0755
edit
dl
rm
cleanfuture.pyc
7510
0644
edit
dl
rm
cleanfuture.pyo
7475
0644
edit
dl
rm
combinerefs.py
4384
0755
edit
dl
rm
combinerefs.pyc
4276
0644
edit
dl
rm
combinerefs.pyo
4241
0644
edit
dl
rm
copytime.py
667
0755
edit
dl
rm
copytime.pyc
945
0644
edit
dl
rm
copytime.pyo
945
0644
edit
dl
rm
crlf.py
614
0755
edit
dl
rm
crlf.pyc
865
0644
edit
dl
rm
crlf.pyo
865
0644
edit
dl
rm
cvsfiles.py
1790
0755
edit
dl
rm
cvsfiles.pyc
2197
0644
edit
dl
rm
cvsfiles.pyo
2197
0644
edit
dl
rm
db2pickle.py
3574
0755
edit
dl
rm
db2pickle.pyc
3552
0644
edit
dl
rm
db2pickle.pyo
3552
0644
edit
dl
rm
diff.py
2002
0644
edit
dl
rm
diff.pyc
2358
0644
edit
dl
rm
diff.pyo
2358
0644
edit
dl
rm
dutree.py
1619
0755
edit
dl
rm
dutree.pyc
2266
0644
edit
dl
rm
dutree.pyo
2266
0644
edit
dl
rm
eptags.py
1487
0755
edit
dl
rm
eptags.pyc
1885
0644
edit
dl
rm
eptags.pyo
1885
0644
edit
dl
rm
finddiv.py
2521
0755
edit
dl
rm
finddiv.pyc
3332
0644
edit
dl
rm
finddiv.pyo
3332
0644
edit
dl
rm
findlinksto.py
1073
0755
edit
dl
rm
findlinksto.pyc
1443
0644
edit
dl
rm
findlinksto.pyo
1443
0644
edit
dl
rm
findnocoding.py
2711
0755
edit
dl
rm
findnocoding.pyc
3148
0644
edit
dl
rm
findnocoding.pyo
3148
0644
edit
dl
rm
fixcid.py
9988
0755
edit
dl
rm
fixcid.pyc
7969
0644
edit
dl
rm
fixcid.pyo
7969
0644
edit
dl
rm
fixdiv.py
13903
0755
edit
dl
rm
fixdiv.pyc
14170
0644
edit
dl
rm
fixdiv.pyo
14080
0644
edit
dl
rm
fixheader.py
1193
0755
edit
dl
rm
fixheader.pyc
1486
0644
edit
dl
rm
fixheader.pyo
1486
0644
edit
dl
rm
fixnotice.py
3054
0755
edit
dl
rm
fixnotice.pyc
3528
0644
edit
dl
rm
fixnotice.pyo
3528
0644
edit
dl
rm
fixps.py
897
0755
edit
dl
rm
fixps.pyc
977
0644
edit
dl
rm
fixps.pyo
977
0644
edit
dl
rm
ftpmirror.py
12857
0755
edit
dl
rm
ftpmirror.pyc
11291
0644
edit
dl
rm
ftpmirror.pyo
11291
0644
edit
dl
rm
google.py
523
0755
edit
dl
rm
google.pyc
802
0644
edit
dl
rm
google.pyo
802
0644
edit
dl
rm
gprof2html.py
2171
0755
edit
dl
rm
gprof2html.pyc
2311
0644
edit
dl
rm
gprof2html.pyo
2311
0644
edit
dl
rm
h2py.py
5753
0755
edit
dl
rm
h2py.pyc
4344
0644
edit
dl
rm
h2py.pyo
4344
0644
edit
dl
rm
hotshotmain.py
1487
0755
edit
dl
rm
hotshotmain.pyc
1867
0644
edit
dl
rm
hotshotmain.pyo
1867
0644
edit
dl
rm
ifdef.py
3720
0755
edit
dl
rm
ifdef.pyc
2331
0644
edit
dl
rm
ifdef.pyo
2331
0644
edit
dl
rm
lfcr.py
622
0755
edit
dl
rm
lfcr.pyc
890
0644
edit
dl
rm
lfcr.pyo
890
0644
edit
dl
rm
linktree.py
2428
0755
edit
dl
rm
linktree.pyc
2055
0644
edit
dl
rm
linktree.pyo
2055
0644
edit
dl
rm
lll.py
750
0755
edit
dl
rm
lll.pyc
963
0644
edit
dl
rm
lll.pyo
963
0644
edit
dl
rm
logmerge.py
5579
0755
edit
dl
rm
logmerge.pyc
5163
0644
edit
dl
rm
logmerge.pyo
5163
0644
edit
dl
rm
mailerdaemon.py
7920
0644
edit
dl
rm
mailerdaemon.pyc
7445
0644
edit
dl
rm
mailerdaemon.pyo
7445
0644
edit
dl
rm
md5sum.py
2389
0755
edit
dl
rm
md5sum.pyc
2956
0644
edit
dl
rm
md5sum.pyo
2956
0644
edit
dl
rm
methfix.py
5466
0755
edit
dl
rm
methfix.pyc
4194
0644
edit
dl
rm
methfix.pyo
4194
0644
edit
dl
rm
mkreal.py
1631
0755
edit
dl
rm
mkreal.pyc
1997
0644
edit
dl
rm
mkreal.pyo
1997
0644
edit
dl
rm
ndiff.py
3812
0755
edit
dl
rm
ndiff.pyc
3891
0644
edit
dl
rm
ndiff.pyo
3891
0644
edit
dl
rm
nm2def.py
2447
0755
edit
dl
rm
nm2def.pyc
2999
0644
edit
dl
rm
nm2def.pyo
2999
0644
edit
dl
rm
objgraph.py
6021
0755
edit
dl
rm
objgraph.pyc
5016
0644
edit
dl
rm
objgraph.pyo
5016
0644
edit
dl
rm
parseentities.py
1723
0755
edit
dl
rm
parseentities.pyc
2092
0644
edit
dl
rm
parseentities.pyo
2092
0644
edit
dl
rm
patchcheck.py
2644
0644
edit
dl
rm
patchcheck.pyc
4033
0644
edit
dl
rm
patchcheck.pyo
4033
0644
edit
dl
rm
pathfix.py
4819
0755
edit
dl
rm
pathfix.pyc
4261
0644
edit
dl
rm
pathfix.pyo
4261
0644
edit
dl
rm
pdeps.py
3940
0755
edit
dl
rm
pdeps.pyc
3277
0644
edit
dl
rm
pdeps.pyo
3277
0644
edit
dl
rm
pickle2db.py
3946
0755
edit
dl
rm
pickle2db.pyc
3875
0644
edit
dl
rm
pickle2db.pyo
3875
0644
edit
dl
rm
pindent.py
17900
0755
edit
dl
rm
pindent.pyc
13020
0644
edit
dl
rm
pindent.pyo
13020
0644
edit
dl
rm
ptags.py
1228
0755
edit
dl
rm
ptags.pyc
1420
0644
edit
dl
rm
ptags.pyo
1420
0644
edit
dl
rm
pysource.py
3850
0755
edit
dl
rm
pysource.pyc
4057
0644
edit
dl
rm
pysource.pyo
4057
0644
edit
dl
rm
redemo.py
5769
0644
edit
dl
rm
redemo.pyc
5280
0644
edit
dl
rm
redemo.pyo
5280
0644
edit
dl
rm
reindent-rst.py
841
0755
edit
dl
rm
reindent-rst.pyc
1149
0644
edit
dl
rm
reindent-rst.pyo
1149
0644
edit
dl
rm
reindent.py
10493
0755
edit
dl
rm
reindent.pyc
8910
0644
edit
dl
rm
reindent.pyo
8869
0644
edit
dl
rm
rgrep.py
1496
0755
edit
dl
rm
rgrep.pyc
1909
0644
edit
dl
rm
rgrep.pyo
1909
0644
edit
dl
rm
setup.py
421
0644
edit
dl
rm
setup.pyc
550
0644
edit
dl
rm
setup.pyo
550
0644
edit
dl
rm
suff.py
625
0755
edit
dl
rm
suff.pyc
916
0644
edit
dl
rm
suff.pyo
916
0644
edit
dl
rm
svneol.py
2934
0755
edit
dl
rm
svneol.pyc
2927
0644
edit
dl
rm
svneol.pyo
2844
0644
edit
dl
rm
texcheck.py
9256
0644
edit
dl
rm
texcheck.pyc
8483
0644
edit
dl
rm
texcheck.pyo
8483
0644
edit
dl
rm
texi2html.py
69827
0755
edit
dl
rm
texi2html.pyc
83869
0644
edit
dl
rm
texi2html.pyo
83869
0644
edit
dl
rm
treesync.py
5787
0755
edit
dl
rm
treesync.pyc
6073
0644
edit
dl
rm
treesync.pyo
6073
0644
edit
dl
rm
untabify.py
1188
0755
edit
dl
rm
untabify.pyc
1571
0644
edit
dl
rm
untabify.pyo
1571
0644
edit
dl
rm
which.py
1634
0755
edit
dl
rm
which.pyc
1659
0644
edit
dl
rm
which.pyo
1659
0644
edit
dl
rm
win_add2path.py
1620
0644
edit
dl
rm
win_add2path.pyc
2139
0644
edit
dl
rm
win_add2path.pyo
2139
0644
edit
dl
rm
xxci.py
2801
0755
edit
dl
rm
xxci.pyc
4065
0644
edit
dl
rm
xxci.pyo
4065
0644
edit
dl
rm
Edit:
/usr/lib64/python2.6/Tools/scripts/reindent.py
(10493B)
#! /usr/bin/env python2.6 # Released to the public domain, by Tim Peters, 03 October 2000. """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. -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 at the end of files. Also ensure the last line ends with a newline. If no paths are given on the command line, reindent operates as a filter, reading a single source file from standard input and writing the transformed source to standard output. In this case, the -d, -r and -v flags are ignored. You can pass one or more file and/or directory paths. When a directory path, all .py files within the directory will be examined, and, if the -r option is given, likewise recursively for subdirectories. If output is not to standard output, reindent overwrites files in place, renaming the originals with a .bak extension. If it finds nothing to change, the file is left alone. If reindent does change a file, the changed file is a fixed-point for future runs (i.e., running reindent on the 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, shutil import sys verbose = 0 recurse = 0 dryrun = 0 makebackup = True def usage(msg=None): if msg is not None: print >> sys.stderr, msg print >> sys.stderr, __doc__ def errprint(*args): sep = "" for arg in args: sys.stderr.write(sep + str(arg)) sep = " " sys.stderr.write("\n") def main(): import getopt global verbose, recurse, dryrun, makebackup try: opts, args = getopt.getopt(sys.argv[1:], "drnvh", ["dryrun", "recurse", "nobackup", "verbose", "help"]) except getopt.error, msg: usage(msg) return for o, a in opts: if o in ('-d', '--dryrun'): 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'): usage() return if not args: r = Reindenter(sys.stdin) r.run() r.write(sys.stdout) return for arg in args: check(arg) def check(file): if os.path.isdir(file) and not os.path.islink(file): if verbose: print "listing directory", file names = os.listdir(file) for name in names: fullname = os.path.join(file, name) if ((recurse and os.path.isdir(fullname) and not os.path.islink(fullname) and not os.path.split(fullname)[1].startswith(".")) or name.lower().endswith(".py")): check(fullname) return if verbose: print "checking", file, "...", try: f = open(file) except IOError, msg: errprint("%s: I/O Error: %s" % (file, str(msg))) return r = Reindenter(f) f.close() if r.run(): if verbose: print "changed." if dryrun: print "But this is a dry run, so leaving it alone." if not dryrun: bak = file + ".bak" if makebackup: shutil.copyfile(file, bak) if verbose: print "backed up", file, "to", bak f = open(file, "w") r.write(f) f.close() if verbose: print "wrote new", file return True else: if verbose: print "unchanged." return False def _rstrip(line, JUNK='\n \t'): """Return line stripped of trailing spaces, tabs, newlines. Note that line.rstrip() instead also strips sundry control characters, but at least one known Emacs user expects to keep junk like that, not mentioning Barry by name or anything <wink>. """ i = len(line) while i > 0 and line[i-1] in JUNK: i -= 1 return line[:i] class Reindenter: def __init__(self, f): self.find_stmt = 1 # next token begins a fresh stmt? self.level = 0 # current indent level # Raw file lines. self.raw = f.readlines() # File lines, rstripped & tab-expanded. Dummy at start is so # that we can use tokenize's 1-based line numbering easily. # Note that a line is all-blank iff it's "\n". self.lines = [_rstrip(line).expandtabs() + "\n" for line in self.raw] self.lines.insert(0, None) self.index = 1 # index into self.lines of next line # List of (lineno, indentlevel) pairs, one for each stmt and # comment line. indentlevel is -1 for comment lines, as a # signal that tokenize doesn't know what to do about them; # indeed, they're our headache! self.stats = [] def run(self): tokenize.tokenize(self.getline, self.tokeneater) # Remove trailing empty lines. lines = self.lines while lines and lines[-1] == "\n": lines.pop() # Sentinel. stats = self.stats stats.append((len(lines), 0)) # Map count of leading spaces to # we want. have2want = {} # Program after transformation. after = self.after = [] # Copy over initial empty lines -- there's nothing to do until # we see a line with *something* on it. i = stats[0][0] after.extend(lines[1:i]) for i in range(len(stats)-1): thisstmt, thislevel = stats[i] nextstmt = stats[i+1][0] have = getlspace(lines[thisstmt]) want = thislevel * 4 if want < 0: # A comment line. if have: # An indented comment line. If we saw the same # indentation before, reuse what it most recently # mapped to. want = have2want.get(have, -1) if want < 0: # Then it probably belongs to the next real stmt. for j in xrange(i+1, len(stats)-1): jline, jlevel = stats[j] if jlevel >= 0: if have == getlspace(lines[jline]): want = jlevel * 4 break if want < 0: # Maybe it's a hanging # comment like this one, # in which case we should shift it like its base # line got shifted. for j in xrange(i-1, -1, -1): jline, jlevel = stats[j] if jlevel >= 0: want = have + getlspace(after[jline-1]) - \ getlspace(lines[jline]) break if want < 0: # Still no luck -- leave it alone. want = have else: want = 0 assert want >= 0 have2want[have] = want diff = want - have if diff == 0 or have == 0: after.extend(lines[thisstmt:nextstmt]) else: for line in lines[thisstmt:nextstmt]: if diff > 0: if line == "\n": after.append(line) else: after.append(" " * diff + line) else: remove = min(getlspace(line), -diff) after.append(line[remove:]) return self.raw != self.after def write(self, f): f.writelines(self.after) # Line-getter for tokenize. def getline(self): if self.index >= len(self.lines): line = "" else: line = self.lines[self.index] self.index += 1 return line # Line-eater for tokenize. def tokeneater(self, type, token, (sline, scol), end, line, INDENT=tokenize.INDENT, DEDENT=tokenize.DEDENT, NEWLINE=tokenize.NEWLINE, COMMENT=tokenize.COMMENT, NL=tokenize.NL): if type == NEWLINE: # A program statement, or ENDMARKER, will eventually follow, # after some (possibly empty) run of tokens of the form # (NL | COMMENT)* (INDENT | DEDENT+)? self.find_stmt = 1 elif type == INDENT: self.find_stmt = 1 self.level += 1 elif type == DEDENT: self.find_stmt = 1 self.level -= 1 elif type == COMMENT: if self.find_stmt: self.stats.append((sline, -1)) # but we're still looking for a new stmt, so leave # find_stmt alone elif type == NL: pass elif self.find_stmt: # This is the first "real token" following a NEWLINE, so it # must be the first token of the next program statement, or an # ENDMARKER. self.find_stmt = 0 if line: # not endmarker self.stats.append((sline, self.level)) # Count number of leading blanks. def getlspace(line): i, n = 0, len(line) while i < n and line[i] == " ": i += 1 return i if __name__ == '__main__': main()
Save
cmd:
run