Debian Codegraph @

pypy/tool/py.cleanup

raw
1 #!/usr/bin/env python
2 import sys, os, stat
3
4 def clean(path):
5 global count
6 try:
7 content = os.listdir(path)
8 except OSError:
9 print >> sys.stderr, "skipping", path
10 return
11 for fn in content:
12 filename = os.path.join(path, fn)
13 st = os.lstat(filename)
14 if stat.S_ISDIR(st.st_mode):
15 clean(filename)
16 if fn == '__pycache__':
17 try:
18 os.rmdir(filename)
19 except OSError:
20 pass
21 elif fn.endswith('.pyc') or fn.endswith('.pyo'):
22 os.unlink(filename)
23 count += 1
24
25 count = 0
26
27 for arg in sys.argv[1:] or ['.']:
28 print "cleaning path", arg, "of .pyc/.pyo/__pycache__ files"
29 clean(arg)
30
31 print "%d files removed" % (count,)