blob: 155a82021dedb40453594e8696585808c0506d29 [file] [log] [blame]
Eli Benderskye936d412015-04-20 15:53:11 -07001# Cleanup all tables and PYC files to ensure no PLY stuff is cached
2from __future__ import print_function
Eli Benderskye460ca82015-05-10 15:25:10 -07003import itertools
Eli Benderskye936d412015-04-20 15:53:11 -07004import 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):
Eli Benderskye460ca82015-05-10 15:25:10 -070012 for file in itertools.chain(dirs, files):
Eli Benderskye936d412015-04-20 15:53:11 -070013 try:
14 for pattern in file_patterns:
15 if fnmatch.fnmatch(file, pattern):
16 fullpath = os.path.join(path, file)
Eli Benderskye460ca82015-05-10 15:25:10 -070017 shutil.rmtree(fullpath, ignore_errors=True)
Eli Benderskye936d412015-04-20 15:53:11 -070018 print('Deleted', fullpath)
19 except OSError:
20 pass
21
22
23if __name__ == "__main__":
24 do_cleanup('.')