blob: 5b0f1c340d0b7ba5342b32694d80479444aaf7cc [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 Benderskydbb018e2015-12-12 14:45:07 -080017 if os.path.isdir(fullpath):
18 shutil.rmtree(fullpath, ignore_errors=False)
19 else:
20 os.unlink(fullpath)
Eli Benderskye936d412015-04-20 15:53:11 -070021 print('Deleted', fullpath)
22 except OSError:
23 pass
24
25
26if __name__ == "__main__":
27 do_cleanup('.')