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.
61 print(msg, file=sys.stderr)
62 print(__doc__, file=sys.stderr)
81 if o in ('-d', '--dryrun'):
83 elif o in ('-r', '--recurse'):
85 elif o in ('-n', '--nobackup'):
87 elif o in ('-v', '--verbose'):
89 elif o in ('-h', '--help'):
100 def check(file): argument
101 if os.path.isdir(file) and not os.path.islink(file):
103 print("listing directory", file)
104 names = os.listdir(file)
106 fullname = os.path.join(file, name)
114 print("checking", file, "...", end=' ')
116 f = open(file)
118 errprint("%s: I/O Error: %s" % (file, str(msg)))
129 bak = file + ".bak"
131 shutil.copyfile(file, bak)
133 print("backed up", file, "to", bak)
134 f = open(file, "w")
138 print("wrote new", file)
154 while i > 0 and line[i-1] in JUNK:
155 i -= 1
164 # Raw file lines.
167 # File lines, rstripped & tab-expanded. Stub at start is so
168 # that we can use tokenize's 1-based line numbering easily.
169 # Note that a line is all-blank iff it's "\n".
170 self.lines = [_rstrip(line).expandtabs() + "\n"
172 self.lines.insert(0, None)
173 self.index = 1 # index into self.lines of next line
176 # comment line. indentlevel is -1 for comment lines, as a
183 # Remove trailing empty lines.
184 lines = self.lines
185 while lines and lines[-1] == "\n":
186 lines.pop()
189 stats.append((len(lines), 0))
194 # Copy over initial empty lines -- there's nothing to do until
197 after.extend(lines[1:i])
198 for i in range(len(stats)-1):
201 have = getlspace(lines[thisstmt])
209 want = have2want.get(have, -1)
212 for j in range(i+1, len(stats)-1):
215 if have == getlspace(lines[jline]):
222 for j in range(i-1, -1, -1):
225 want = have + getlspace(after[jline-1]) - \
226 getlspace(lines[jline])
229 # Still no luck -- leave it alone.
235 diff = want - have
237 after.extend(lines[thisstmt:nextstmt])
239 for line in lines[thisstmt:nextstmt]:
246 remove = min(getlspace(line), -diff)
253 # Line-getter for tokenize.
255 if self.index >= len(self.lines):
258 line = self.lines[self.index]
262 # Line-eater for tokenize.
283 self.level -= 1
287 self.stats.append((sline, -1))