| 62 | |
| 63 | |
| 64 | def list_files(files, recursive=False, extensions=None, exclude=None): |
| 65 | if extensions is None: |
| 66 | extensions = [] |
| 67 | if exclude is None: |
| 68 | exclude = [] |
| 69 | |
| 70 | out = [] |
| 71 | for file in files: |
| 72 | if recursive and os.path.isdir(file): |
| 73 | for dirpath, dnames, fnames in os.walk(file): |
| 74 | fpaths = [ |
| 75 | os.path.relpath(os.path.join(dirpath, fname), os.getcwd()) |
| 76 | for fname in fnames |
| 77 | ] |
| 78 | for pattern in exclude: |
| 79 | # os.walk() supports trimming down the dnames list |
| 80 | # by modifying it in-place, |
| 81 | # to avoid unnecessary directory listings. |
| 82 | dnames[:] = [ |
| 83 | x |
| 84 | for x in dnames |
| 85 | if not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) |
| 86 | ] |
| 87 | fpaths = [x for x in fpaths if not fnmatch.fnmatch(x, pattern)] |
| 88 | |
| 89 | for f in fpaths: |
| 90 | ext = os.path.splitext(f)[1][1:] |
| 91 | if ext in extensions: |
| 92 | out.append(f) |
| 93 | else: |
| 94 | out.append(file) |
| 95 | return out |
| 96 | |
| 97 | |
| 98 | def make_diff(file, original, reformatted): |