summaryrefslogtreecommitdiffstats
path: root/Mac/scripts/zappycfiles.py
blob: b5af2d0423189bf198ebcb381eabe106827d78a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/local/bin/python
"""Recursively zap all .pyc and .pyo files"""
import os
import sys
import EasyDialogs

# set doit true to actually delete files
# set doit false to just print what would be deleted
doit = 1

def main():
	if not sys.argv[1:]:
		if os.name == 'mac':
			dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in')
			if not dir:
				sys.exit(0)
			zappyc(dir)
		else:
			print 'Usage: zappyc dir ...'
			sys.exit(1)
	for dir in sys.argv[1:]:
		zappyc(dir)

def zappyc(dir):
	os.path.walk(dir, walker, None)
	
def walker(dummy, top, names):
	for name in names:
		if name[-4:] in ('.pyc', '.pyo'):
			path = os.path.join(top, name)
			print 'Zapping', path
			if doit:
				os.unlink(path)
				
if __name__ == '__main__':
	main()