blob: 4637159049684a1f623b70a831151bdfe7eb2770 [file] [log] [blame]
Jack Jansenf1148f02002-08-09 10:17:28 +00001#!/usr/local/bin/python
Jack Jansen3337ea72002-09-06 20:23:09 +00002"""Recursively zap all .pyc and .pyo files"""
Jack Jansendfebb272001-01-23 22:45:52 +00003import os
4import sys
Jack Jansenb340acf2003-01-26 21:40:00 +00005import EasyDialogs
Jack Jansendfebb272001-01-23 22:45:52 +00006
Jack Jansenf1148f02002-08-09 10:17:28 +00007# set doit true to actually delete files
8# set doit false to just print what would be deleted
Jack Jansendfebb272001-01-23 22:45:52 +00009doit = 1
10
11def main():
Jack Jansenf1148f02002-08-09 10:17:28 +000012 if not sys.argv[1:]:
13 if os.name == 'mac':
14 import macfs
Jack Jansenb340acf2003-01-26 21:40:00 +000015 dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in')
16 if not dir:
Jack Jansenf1148f02002-08-09 10:17:28 +000017 sys.exit(0)
Jack Jansenf1148f02002-08-09 10:17:28 +000018 zappyc(dir)
19 else:
Jack Jansendfebb272001-01-23 22:45:52 +000020 print 'Usage: zappyc dir ...'
21 sys.exit(1)
Jack Jansenf1148f02002-08-09 10:17:28 +000022 for dir in sys.argv[1:]:
23 zappyc(dir)
Jack Jansendfebb272001-01-23 22:45:52 +000024
25def zappyc(dir):
26 os.path.walk(dir, walker, None)
27
28def walker(dummy, top, names):
29 for name in names:
Jack Jansen3337ea72002-09-06 20:23:09 +000030 if name[-4:] in ('.pyc', '.pyo'):
Jack Jansendfebb272001-01-23 22:45:52 +000031 path = os.path.join(top, name)
32 print 'Zapping', path
33 if doit:
34 os.unlink(path)
35
36if __name__ == '__main__':
37 main()
38