From 3b052e9f7fbb265899f9cd89d0e50d13b49fd04c Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 28 Apr 2009 23:00:57 +0200 Subject: [PATCH] extend py.cleanup to supply a list of extensions to clean --HG-- branch : trunk --- py/cmdline/pycleanup.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/py/cmdline/pycleanup.py b/py/cmdline/pycleanup.py index 953d28137..c5a137899 100755 --- a/py/cmdline/pycleanup.py +++ b/py/cmdline/pycleanup.py @@ -11,11 +11,26 @@ import py def main(): parser = py.compat.optparse.OptionParser(usage=__doc__) + parser.add_option("-e", "--remove", dest="ext", default=".pyc", action="store", + help="remove files with the given comma-separated list of extensions" + ) + parser.add_option("-n", "--dryrun", dest="dryrun", default=False, + action="store_true", + help="display would-be-removed filenames" + ) (options, args) = parser.parse_args() if not args: args = ["."] + ext = options.ext.split(",") + def shouldremove(p): + return p.ext in ext + for arg in args: path = py.path.local(arg) - print "cleaning path", path - for x in path.visit('*.pyc', lambda x: x.check(dotfile=0, link=0)): - x.remove() + print "cleaning path", path, "of extensions", ext + for x in path.visit(shouldremove, lambda x: x.check(dotfile=0, link=0)): + if options.dryrun: + print "would remove", x + else: + print "removing", x + x.remove()