| 35 | |
| 36 | |
| 37 | def list_files(files, recursive=False, extensions=None, exclude=None): |
| 38 | if extensions is None: |
| 39 | extensions = [] |
| 40 | if exclude is None: |
| 41 | exclude = [] |
| 42 | |
| 43 | out = [] |
| 44 | for file in files: |
| 45 | if recursive and os.path.isdir(file): |
| 46 | for dirpath, dnames, fnames in os.walk(file): |
| 47 | fpaths = [os.path.join(dirpath, fname) for fname in fnames] |
| 48 | for pattern in exclude: |
| 49 | # os.walk() supports trimming down the dnames list |
| 50 | # by modifying it in-place, |
| 51 | # to avoid unnecessary directory listings. |
| 52 | dnames[:] = [ |
| 53 | x for x in dnames |
| 54 | if |
| 55 | not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) |
| 56 | ] |
| 57 | fpaths = [ |
| 58 | x for x in fpaths if not fnmatch.fnmatch(x, pattern) |
| 59 | ] |
| 60 | for f in fpaths: |
| 61 | ext = os.path.splitext(f)[1][1:] |
| 62 | if ext in extensions: |
| 63 | out.append(f) |
| 64 | else: |
| 65 | out.append(file) |
| 66 | return out |
| 67 | |
| 68 | |
| 69 | def make_diff(file, original, reformatted): |