]>
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': | |
13 | import macfs | |
14 | fss, ok = macfs.GetDirectory('Directory to zap pyc files in') | |
15 | if not ok: | |
16 | sys.exit(0) | |
17 | dir = fss.as_pathname() | |
18 | zappyc(dir) | |
19 | else: | |
20 | print 'Usage: zappyc dir ...' | |
21 | sys.exit(1) | |
22 | for dir in sys.argv[1:]: | |
23 | zappyc(dir) | |
24 | ||
25 | def zappyc(dir): | |
26 | os.path.walk(dir, walker, None) | |
27 | ||
28 | def walker(dummy, top, names): | |
29 | for name in names: | |
30 | if name[-4:] in ('.pyc', '.pyo'): | |
31 | path = os.path.join(top, name) | |
32 | print 'Zapping', path | |
33 | if doit: | |
34 | os.unlink(path) | |
35 | ||
36 | if __name__ == '__main__': | |
37 | main() | |
38 |