1
#!/usr/bin/env python2.3
3
# SchoolTool - common information systems platform for school administration
4
# Copyright (c) 2003 Shuttleworth Foundation
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
Recursively removes .pyc and .pyo files without a corresponding .py file.
23
Usage: %(progname)s [options] [dirname ...]
26
-h, --help this message
27
-v, --verbose print names of files before they are removed (default)
28
-q, --quiet the opposite of --verbose
29
-n, --dry-run do not actually remove the files (implies --verbose)
31
If dirname is ommitted, %(progname)s starts looking for stale
32
bytecode files in the current directory.
40
def main(argv=sys.argv):
41
progname = os.path.basename(argv[0])
42
helpmsg = __doc__.strip() % {'progname': progname}
46
opts, args = getopt.getopt(argv[1:], 'vqnh',
47
['verbose', 'quiet', 'dry-run', 'help'])
48
except getopt.error, e:
49
print >> sys.stderr, e
50
print >> sys.stderr, 'try %s --help' % progname
53
if k in ('-v', '--verbose'):
55
elif k in ('-q', '--quiet'):
57
elif k in ('-n', '--dry-run'):
60
elif k in ('-h', '--help'):
66
for dirpath, dirnames, filenames in os.walk(root):
67
filenames = map(os.path.normcase, filenames)
68
for filename in filenames:
69
if filename.endswith('.pyc') or filename.endswith('pyo'):
70
sourcename = filename[:-1]
71
if sourcename not in filenames:
72
fullname = os.path.join(dirpath, filename)
74
print "Removing", fullname
79
print >> sys.stderr, ("%s: %s: %s" %
80
(progname, fullname, e))
83
if __name__ == '__main__':