2002-08-09 07:17:28 -03:00
|
|
|
#!/usr/local/bin/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
|
2003-01-26 17:40:00 -04:00
|
|
|
import EasyDialogs
|
2001-01-23 18:45:52 -04:00
|
|
|
|
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():
|
2002-08-09 07:17:28 -03:00
|
|
|
if not sys.argv[1:]:
|
|
|
|
if os.name == 'mac':
|
2003-01-26 17:40:00 -04:00
|
|
|
dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in')
|
|
|
|
if not dir:
|
2002-08-09 07:17:28 -03:00
|
|
|
sys.exit(0)
|
|
|
|
zappyc(dir)
|
|
|
|
else:
|
2001-01-23 18:45:52 -04:00
|
|
|
print 'Usage: zappyc dir ...'
|
|
|
|
sys.exit(1)
|
2002-08-09 07:17:28 -03:00
|
|
|
for dir in sys.argv[1:]:
|
|
|
|
zappyc(dir)
|
2001-01-23 18:45:52 -04:00
|
|
|
|
|
|
|
def zappyc(dir):
|
|
|
|
os.path.walk(dir, walker, None)
|
|
|
|
|
|
|
|
def walker(dummy, top, names):
|
|
|
|
for name in names:
|
2002-09-06 17:23:09 -03:00
|
|
|
if name[-4:] in ('.pyc', '.pyo'):
|
2001-01-23 18:45:52 -04:00
|
|
|
path = os.path.join(top, name)
|
|
|
|
print 'Zapping', path
|
|
|
|
if doit:
|
|
|
|
os.unlink(path)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|