(file)
| 76 | check(arg) |
| 77 | |
| 78 | def check(file): |
| 79 | if os.path.isdir(file) and not os.path.islink(file): |
| 80 | if verbose: |
| 81 | print("listing directory", file) |
| 82 | names = os.listdir(file) |
| 83 | for name in names: |
| 84 | fullname = os.path.join(file, name) |
| 85 | if ((recurse and os.path.isdir(fullname) and |
| 86 | not os.path.islink(fullname)) |
| 87 | or name.lower().endswith(".py")): |
| 88 | check(fullname) |
| 89 | return |
| 90 | |
| 91 | if verbose: |
| 92 | print("checking", file, "...", end=' ') |
| 93 | try: |
| 94 | f = open(file) |
| 95 | except IOError as msg: |
| 96 | errprint("%r: I/O Error: %s" % (file, str(msg))) |
| 97 | return |
| 98 | |
| 99 | with f: |
| 100 | ff = FutureFinder(f, file) |
| 101 | changed = ff.run() |
| 102 | if changed: |
| 103 | ff.gettherest() |
| 104 | if changed: |
| 105 | if verbose: |
| 106 | print("changed.") |
| 107 | if dryrun: |
| 108 | print("But this is a dry run, so leaving it alone.") |
| 109 | for s, e, line in changed: |
| 110 | print("%r lines %d-%d" % (file, s+1, e+1)) |
| 111 | for i in range(s, e+1): |
| 112 | print(ff.lines[i], end=' ') |
| 113 | if line is None: |
| 114 | print("-- deleted") |
| 115 | else: |
| 116 | print("-- change to:") |
| 117 | print(line, end=' ') |
| 118 | if not dryrun: |
| 119 | bak = file + ".bak" |
| 120 | if os.path.exists(bak): |
| 121 | os.remove(bak) |
| 122 | os.rename(file, bak) |
| 123 | if verbose: |
| 124 | print("renamed", file, "to", bak) |
| 125 | with open(file, "w") as g: |
| 126 | ff.write(g) |
| 127 | if verbose: |
| 128 | print("wrote new", file) |
| 129 | else: |
| 130 | if verbose: |
| 131 | print("unchanged.") |
| 132 | |
| 133 | class FutureFinder: |
| 134 |
no test coverage detected