Eli Bendersky | e936d41 | 2015-04-20 15:53:11 -0700 | [diff] [blame^] | 1 | # Cleanup all tables and PYC files to ensure no PLY stuff is cached |
| 2 | from __future__ import print_function |
| 3 | import fnmatch |
| 4 | import os, shutil |
| 5 | |
| 6 | file_patterns = ('yacctab.*', 'lextab.*', '*.pyc', '__pycache__') |
| 7 | |
| 8 | |
| 9 | def do_cleanup(root): |
| 10 | for path, dirs, files in os.walk(root): |
| 11 | for file in files: |
| 12 | try: |
| 13 | for pattern in file_patterns: |
| 14 | if fnmatch.fnmatch(file, pattern): |
| 15 | fullpath = os.path.join(path, file) |
| 16 | os.remove(fullpath) |
| 17 | print('Deleted', fullpath) |
| 18 | except OSError: |
| 19 | pass |
| 20 | |
| 21 | |
| 22 | if __name__ == "__main__": |
| 23 | do_cleanup('.') |