PageRenderTime 243ms CodeModel.GetById 121ms app.highlight 3ms RepoModel.GetById 117ms app.codeStats 0ms

/Mac/scripts/zappycfiles.py

http://unladen-swallow.googlecode.com/
Python | 36 lines | 27 code | 5 blank | 4 comment | 13 complexity | 0f5f86e91255ebd81ab584df28c13761 MD5 | raw file
 1#!/usr/local/bin/python
 2"""Recursively zap all .pyc and .pyo files"""
 3import os
 4import sys
 5
 6# set doit true to actually delete files
 7# set doit false to just print what would be deleted
 8doit = 1
 9
10def main():
11    if not sys.argv[1:]:
12        if os.name == 'mac':
13            import EasyDialogs
14            dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in')
15            if not dir:
16                sys.exit(0)
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
24def zappyc(dir):
25    os.path.walk(dir, walker, None)
26
27def 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
35if __name__ == '__main__':
36    main()