2010-03-11 18:33:25 -04:00
|
|
|
#!/usr/bin/env python
|
2002-09-06 17:23:09 -03:00
|
|
|
"""Recursively zap all .pyc and .pyo files"""
|
2001-01-23 18:45:52 -04:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2002-08-09 07:17:28 -03:00
|
|
|
# set doit true to actually delete files
|
|
|
|
# set doit false to just print what would be deleted
|
2001-01-23 18:45:52 -04:00
|
|
|
doit = 1
|
|
|
|
|
|
|
|
def main():
|
2004-07-18 03:16:08 -03:00
|
|
|
if not sys.argv[1:]:
|
2010-05-05 16:09:31 -03:00
|
|
|
print 'Usage: zappyc dir ...'
|
|
|
|
sys.exit(1)
|
2004-07-18 03:16:08 -03:00
|
|
|
for dir in sys.argv[1:]:
|
|
|
|
zappyc(dir)
|
2001-01-23 18:45:52 -04:00
|
|
|
|
|
|
|
def zappyc(dir):
|
2004-07-18 03:16:08 -03:00
|
|
|
os.path.walk(dir, walker, None)
|
|
|
|
|
2001-01-23 18:45:52 -04:00
|
|
|
def walker(dummy, top, names):
|
2004-07-18 03:16:08 -03:00
|
|
|
for name in names:
|
|
|
|
if name[-4:] in ('.pyc', '.pyo'):
|
|
|
|
path = os.path.join(top, name)
|
|
|
|
print 'Zapping', path
|
|
|
|
if doit:
|
|
|
|
os.unlink(path)
|
|
|
|
|
2001-01-23 18:45:52 -04:00
|
|
|
if __name__ == '__main__':
|
2004-07-18 03:16:08 -03:00
|
|
|
main()
|