1# Cleanup all tables and PYC files to ensure no PLY stuff is cached 2from __future__ import print_function 3import itertools 4import fnmatch 5import os, shutil 6 7file_patterns = ('yacctab.*', 'lextab.*', '*.pyc', '__pycache__') 8 9 10def do_cleanup(root): 11 for path, dirs, files in os.walk(root): 12 for file in itertools.chain(dirs, files): 13 try: 14 for pattern in file_patterns: 15 if fnmatch.fnmatch(file, pattern): 16 fullpath = os.path.join(path, file) 17 if os.path.isdir(fullpath): 18 shutil.rmtree(fullpath, ignore_errors=False) 19 else: 20 os.unlink(fullpath) 21 print('Deleted', fullpath) 22 except OSError: 23 pass 24 25 26if __name__ == "__main__": 27 do_cleanup('.') 28