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
|
|
|
|
|
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:]:
|
|
|
|
if os.name == 'mac':
|
|
|
|
import EasyDialogs
|
|
|
|
dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in')
|
|
|
|
if not dir:
|
|
|
|
sys.exit(0)
|
|
|
|
zappyc(dir)
|
|
|
|
else:
|
2007-08-30 15:39:28 -03:00
|
|
|
print('Usage: zappyc dir ...')
|
2004-07-18 03:16:08 -03:00
|
|
|
sys.exit(1)
|
|
|
|
for dir in sys.argv[1:]:
|
|
|
|
zappyc(dir)
|
2001-01-23 18:45:52 -04:00
|
|
|
|
|
|
|
def zappyc(dir):
|
2008-05-09 17:00:17 -03:00
|
|
|
os.walk(dir, walker, None)
|
2004-07-18 03:16:08 -03:00
|
|
|
|
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)
|
2007-08-30 15:39:28 -03:00
|
|
|
print('Zapping', path)
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|