• Home
  • History
  • Annotate
  • Raw
  • Download

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 (--newline) Newline. Specify the newline character to use (CRLF, LF).
12 Default is the same as the original file.
13 -h (--help) Help. Print this usage information and exit.
15 Change Python (.py) files to use 4-space indents and no hard tab characters.
16 Also trim excess spaces and tabs from ends of lines, and remove empty lines
20 reading a single source file from standard input and writing the transformed
21 source to standard output. In this case, the -d, -r and -v flags are
24 You can pass one or more file and/or directory paths. When a directory
25 path, all .py files within the directory will be examined, and, if the -r
30 change, the file is left alone. If reindent does change a file, the changed
31 file is a fixed-point for future runs (i.e., running reindent on the
32 resulting .py file won't change it again).
35 lines. So long as the input files get a clean bill of health from
38 The backup file is a copy of the one that is being reindented. The ".bak"
39 file is generated with shutil.copy(), but some corner cases regarding
40 user/group and permissions could leave the backup file more readable than
41 you'd prefer. You can always use the --nobackup option to prevent this.
55 # A specified newline to be used in the output (set by --newline option)
62 print(msg, file=sys.stderr)
79 if o in ('-d', '--dryrun'):
81 elif o in ('-r', '--recurse'):
83 elif o in ('-n', '--nobackup'):
85 elif o in ('-v', '--verbose'):
87 elif o in ('--newline',):
92 elif o in ('-h', '--help'):
104 def check(file): argument
105 if os.path.isdir(file) and not os.path.islink(file):
107 print("listing directory", file)
108 names = os.listdir(file)
110 fullname = os.path.join(file, name)
119 print("checking", file, "...", end=' ')
120 with open(file, 'rb') as f:
124 errprint("%s: SyntaxError: %s" % (file, str(se)))
127 with open(file, encoding=encoding) as f:
130 errprint("%s: I/O Error: %s" % (file, str(msg)))
135 errprint("%s: mixed newlines detected; cannot continue without --newline" % file)
144 bak = file + ".bak"
146 shutil.copyfile(file, bak)
148 print("backed up", file, "to", bak)
149 with open(file, "w", encoding=encoding, newline=newline) as f:
152 print("wrote new", file)
169 while i > 0 and line[i - 1] in JUNK:
170 i -= 1
180 # Raw file lines.
183 # File lines, rstripped & tab-expanded. Dummy at start is so
184 # that we can use tokenize's 1-based line numbering easily.
185 # Note that a line is all-blank iff it's "\n".
186 self.lines = [_rstrip(line).expandtabs() + "\n"
188 self.lines.insert(0, None)
189 self.index = 1 # index into self.lines of next line
192 # comment line. indentlevel is -1 for comment lines, as a
197 # Save the newlines found in the file so they can be used to
205 # Remove trailing empty lines.
206 lines = self.lines
207 while lines and lines[-1] == "\n":
208 lines.pop()
211 stats.append((len(lines), 0))
216 # Copy over initial empty lines -- there's nothing to do until
219 after.extend(lines[1:i])
220 for i in range(len(stats) - 1):
223 have = getlspace(lines[thisstmt])
231 want = have2want.get(have, -1)
234 for j in range(i + 1, len(stats) - 1):
237 if have == getlspace(lines[jline]):
244 for j in range(i - 1, -1, -1):
247 want = have + (getlspace(after[jline - 1]) -
248 getlspace(lines[jline]))
251 # Still no luck -- leave it alone.
257 diff = want - have
259 after.extend(lines[thisstmt:nextstmt])
261 for line in lines[thisstmt:nextstmt]:
268 remove = min(getlspace(line), -diff)
275 # Line-getter for tokenize.
277 if self.index >= len(self.lines):
280 line = self.lines[self.index]
284 # Line-eater for tokenize.
304 self.level -= 1
308 self.stats.append((slinecol[0], -1))