(file)
| 102 | |
| 103 | |
| 104 | def check(file): |
| 105 | if os.path.isdir(file) and not os.path.islink(file): |
| 106 | if verbose: |
| 107 | print("listing directory", file) |
| 108 | names = os.listdir(file) |
| 109 | for name in names: |
| 110 | fullname = os.path.join(file, name) |
| 111 | if ((recurse and os.path.isdir(fullname) and |
| 112 | not os.path.islink(fullname) and |
| 113 | not os.path.split(fullname)[1].startswith(".")) |
| 114 | or name.lower().endswith(".py")): |
| 115 | check(fullname) |
| 116 | return |
| 117 | |
| 118 | if verbose: |
| 119 | print("checking", file, "...", end=' ') |
| 120 | with open(file, 'rb') as f: |
| 121 | try: |
| 122 | encoding, _ = tokenize.detect_encoding(f.readline) |
| 123 | except SyntaxError as se: |
| 124 | errprint("%s: SyntaxError: %s" % (file, str(se))) |
| 125 | return |
| 126 | try: |
| 127 | with open(file, encoding=encoding) as f: |
| 128 | r = Reindenter(f) |
| 129 | except IOError as msg: |
| 130 | errprint("%s: I/O Error: %s" % (file, str(msg))) |
| 131 | return |
| 132 | |
| 133 | newline = spec_newline if spec_newline else r.newlines |
| 134 | if isinstance(newline, tuple): |
| 135 | errprint("%s: mixed newlines detected; cannot continue without --newline" % file) |
| 136 | return |
| 137 | |
| 138 | if r.run(): |
| 139 | if verbose: |
| 140 | print("changed.") |
| 141 | if dryrun: |
| 142 | print("But this is a dry run, so leaving it alone.") |
| 143 | if not dryrun: |
| 144 | bak = file + ".bak" |
| 145 | if makebackup: |
| 146 | shutil.copyfile(file, bak) |
| 147 | if verbose: |
| 148 | print("backed up", file, "to", bak) |
| 149 | with open(file, "w", encoding=encoding, newline=newline) as f: |
| 150 | r.write(f) |
| 151 | if verbose: |
| 152 | print("wrote new", file) |
| 153 | return True |
| 154 | else: |
| 155 | if verbose: |
| 156 | print("unchanged.") |
| 157 | return False |
| 158 | |
| 159 | |
| 160 | def _rstrip(line, JUNK='\n \t'): |
no test coverage detected
searching dependent graphs…