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
|
|
|
|
|
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():
|
2004-07-18 08:16:08 +02: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 20:39:28 +02:00
|
|
|
print('Usage: zappyc dir ...')
|
2004-07-18 08:16:08 +02:00
|
|
|
sys.exit(1)
|
|
|
|
for dir in sys.argv[1:]:
|
|
|
|
zappyc(dir)
|
2001-01-23 23:45:52 +01:00
|
|
|
|
|
|
|
def zappyc(dir):
|
2008-05-09 22:00:17 +02:00
|
|
|
os.walk(dir, walker, None)
|
2004-07-18 08:16:08 +02:00
|
|
|
|
2001-01-23 23:45:52 +01:00
|
|
|
def walker(dummy, top, names):
|
2004-07-18 08:16:08 +02:00
|
|
|
for name in names:
|
|
|
|
if name[-4:] in ('.pyc', '.pyo'):
|
|
|
|
path = os.path.join(top, name)
|
2007-08-30 20:39:28 +02:00
|
|
|
print('Zapping', path)
|
2004-07-18 08:16:08 +02:00
|
|
|
if doit:
|
|
|
|
os.unlink(path)
|
|
|
|
|
2001-01-23 23:45:52 +01:00
|
|
|
if __name__ == '__main__':
|
2004-07-18 08:16:08 +02:00
|
|
|
main()
|