diff options
Diffstat (limited to 'demo/py.cleanup')
-rwxr-xr-x | demo/py.cleanup | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/demo/py.cleanup b/demo/py.cleanup new file mode 100755 index 0000000..512389f --- /dev/null +++ b/demo/py.cleanup @@ -0,0 +1,31 @@ +#! /usr/bin/env python +import sys, os, stat +from bsdopendirtype import opendir + +def clean(path): + global count + try: + content = opendir(path) + except OSError: + print >> sys.stderr, "skipping", path + return + for filename, smode in content: + if stat.S_ISDIR(smode): + clean(filename) + if filename.endswith('/__pycache__'): + try: + os.rmdir(filename) + except OSError: + pass + elif (filename.endswith('.pyc') or filename.endswith('.pyo') or + filename.endswith('.pyc~') or filename.endswith('.pyo~')): + os.unlink(filename) + count += 1 + +count = 0 + +for arg in sys.argv[1:] or ['.']: + print "cleaning path", arg, "of .pyc/.pyo/__pycache__ files" + clean(arg) + +print "%d files removed" % (count,) |