2002-08-09 12:17:28 +02:00
|
|
|
#!/usr/local/bin/python
|
2002-09-06 22:23:09 +02:00
|
|
|
"""Recursively zap all .pyc and .pyo files"""
|
2001-01-23 23:45:52 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2003-01-26 22:40:00 +01:00
|
|
|
import EasyDialogs
|
2001-01-23 23:45:52 +01:00
|
|
|
|
2002-08-09 12:17:28 +02:00
|
|
|
# set doit true to actually delete files
|
|
|
|
# set doit false to just print what would be deleted
|
2001-01-23 23:45:52 +01:00
|
|
|
doit = 1
|
|
|
|
|
|
|
|
def main():
|
2002-08-09 12:17:28 +02:00
|
|
|
if not sys.argv[1:]:
|
|
|
|
if os.name == 'mac':
|
2003-01-26 22:40:00 +01:00
|
|
|
dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in')
|
|
|
|
if not dir:
|
2002-08-09 12:17:28 +02:00
|
|
|
sys.exit(0)
|
|
|
|
zappyc(dir)
|
|
|
|
else:
|
2001-01-23 23:45:52 +01:00
|
|
|
print 'Usage: zappyc dir ...'
|
|
|
|
sys.exit(1)
|
2002-08-09 12:17:28 +02:00
|
|
|
for dir in sys.argv[1:]:
|
|
|
|
zappyc(dir)
|
2001-01-23 23:45:52 +01:00
|
|
|
|
|
|
|
def zappyc(dir):
|
|
|
|
os.path.walk(dir, walker, None)
|
|
|
|
|
|
|
|
def walker(dummy, top, names):
|
|
|
|
for name in names:
|
2002-09-06 22:23:09 +02:00
|
|
|
if name[-4:] in ('.pyc', '.pyo'):
|
2001-01-23 23:45:52 +01:00
|
|
|
path = os.path.join(top, name)
|
|
|
|
print 'Zapping', path
|
|
|
|
if doit:
|
|
|
|
os.unlink(path)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|