]>
Commit | Line | Data |
---|---|---|
1e4a197e RD |
1 | #!/usr/local/bin/python |
2 | """Recursively zap all .pyc and .pyo files""" | |
3 | import os | |
4 | import sys | |
5 | ||
6 | # set doit true to actually delete files | |
7 | # set doit false to just print what would be deleted | |
8 | doit = 1 | |
9 | ||
10 | def main(): | |
11 | if not sys.argv[1:]: | |
12 | if os.name == 'mac': | |
46456f61 RD |
13 | import EasyDialogs |
14 | dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in') | |
15 | if not dir: | |
1e4a197e | 16 | sys.exit(0) |
1e4a197e RD |
17 | zappyc(dir) |
18 | else: | |
19 | print 'Usage: zappyc dir ...' | |
20 | sys.exit(1) | |
21 | for dir in sys.argv[1:]: | |
22 | zappyc(dir) | |
23 | ||
24 | def zappyc(dir): | |
25 | os.path.walk(dir, walker, None) | |
26 | ||
27 | def walker(dummy, top, names): | |
28 | for name in names: | |
29 | if name[-4:] in ('.pyc', '.pyo'): | |
30 | path = os.path.join(top, name) | |
31 | print 'Zapping', path | |
32 | if doit: | |
33 | os.unlink(path) | |
34 | ||
35 | if __name__ == '__main__': | |
36 | main() | |
37 |