Lines Matching +full:file +full:- +full:lines
5 """reindent [-d][-r][-v] [ path ... ]
7 -d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
8 -r (--recurse) Recurse. Search for all .py files in subdirectories too.
9 -n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
10 -v (--verbose) Verbose. Print informative msgs; else no output.
11 -h (--help) Help. Print this usage information and exit.
13 Change Python (.py) files to use 4-space indents and no hard tab characters.
14 Also trim excess spaces and tabs from ends of lines, and remove empty lines
18 reading a single source file from standard input and writing the transformed
19 source to standard output. In this case, the -d, -r and -v flags are
22 You can pass one or more file and/or directory paths. When a directory
23 path, all .py files within the directory will be examined, and, if the -r
28 change, the file is left alone. If reindent does change a file, the changed
29 file is a fixed-point for future runs (i.e., running reindent on the
30 resulting .py file won't change it again).
33 lines. So long as the input files get a clean bill of health from
36 The backup file is a copy of the one that is being reindented. The ".bak"
37 file is generated with shutil.copy(), but some corner cases regarding
38 user/group and permissions could leave the backup file more readable that
39 you'd prefer. You can always use the --nobackup option to prevent this.
75 if o in ('-d', '--dryrun'):
77 elif o in ('-r', '--recurse'):
79 elif o in ('-n', '--nobackup'):
81 elif o in ('-v', '--verbose'):
83 elif o in ('-h', '--help'):
94 def check(file): argument
95 if os.path.isdir(file) and not os.path.islink(file):
97 print "listing directory", file
98 names = os.listdir(file)
100 fullname = os.path.join(file, name)
108 print "checking", file, "...",
110 f = open(file)
112 errprint("%s: I/O Error: %s" % (file, str(msg)))
123 bak = file + ".bak"
125 shutil.copyfile(file, bak)
127 print "backed up", file, "to", bak
128 f = open(file, "w")
132 print "wrote new", file
148 while i > 0 and line[i-1] in JUNK:
149 i -= 1
158 # Raw file lines.
161 # File lines, rstripped & tab-expanded. Dummy at start is so
162 # that we can use tokenize's 1-based line numbering easily.
163 # Note that a line is all-blank iff it's "\n".
164 self.lines = [_rstrip(line).expandtabs() + "\n"
166 self.lines.insert(0, None)
167 self.index = 1 # index into self.lines of next line
170 # comment line. indentlevel is -1 for comment lines, as a
177 # Remove trailing empty lines.
178 lines = self.lines
179 while lines and lines[-1] == "\n":
180 lines.pop()
183 stats.append((len(lines), 0))
188 # Copy over initial empty lines -- there's nothing to do until
191 after.extend(lines[1:i])
192 for i in range(len(stats)-1):
195 have = getlspace(lines[thisstmt])
203 want = have2want.get(have, -1)
206 for j in xrange(i+1, len(stats)-1):
209 if have == getlspace(lines[jline]):
216 for j in xrange(i-1, -1, -1):
219 want = have + getlspace(after[jline-1]) - \
220 getlspace(lines[jline])
223 # Still no luck -- leave it alone.
229 diff = want - have
231 after.extend(lines[thisstmt:nextstmt])
233 for line in lines[thisstmt:nextstmt]:
240 remove = min(getlspace(line), -diff)
247 # Line-getter for tokenize.
249 if self.index >= len(self.lines):
252 line = self.lines[self.index]
256 # Line-eater for tokenize.
276 self.level -= 1
280 self.stats.append((sline, -1))