Mercurial > cpython-lru_cache-weakref
annotate Mac/scripts/zappycfiles.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | f6785bce54b5 |
| children |
| rev | line source |
|---|---|
|
59518
ef48e48f066e
normalize shebang lines to #!/usr/bin/env python
Benjamin Peterson <benjamin@python.org>
parents:
32736
diff
changeset
|
1 #!/usr/bin/env python |
| 25145 | 2 """Recursively zap all .pyc and .pyo files""" |
|
16186
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
3 import os |
|
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
4 import sys |
|
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
5 |
|
24693
e71bbba0a0b9
Patch by Russel Owen: if we have command line arguments zap pyc files
Jack Jansen <jack.jansen@cwi.nl>
parents:
16186
diff
changeset
|
6 # set doit true to actually delete files |
|
e71bbba0a0b9
Patch by Russel Owen: if we have command line arguments zap pyc files
Jack Jansen <jack.jansen@cwi.nl>
parents:
16186
diff
changeset
|
7 # set doit false to just print what would be deleted |
|
16186
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
8 doit = 1 |
|
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
9 |
|
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
10 def main(): |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
11 if not sys.argv[1:]: |
|
61258
f6785bce54b5
In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59518
diff
changeset
|
12 print 'Usage: zappyc dir ...' |
|
f6785bce54b5
In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59518
diff
changeset
|
13 sys.exit(1) |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
14 for dir in sys.argv[1:]: |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
15 zappyc(dir) |
|
16186
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
16 |
|
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
17 def zappyc(dir): |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
18 os.path.walk(dir, walker, None) |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
19 |
|
16186
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
20 def walker(dummy, top, names): |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
21 for name in names: |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
22 if name[-4:] in ('.pyc', '.pyo'): |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
23 path = os.path.join(top, name) |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
24 print 'Zapping', path |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
25 if doit: |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
26 os.unlink(path) |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
27 |
|
16186
01e8a6d8da8b
Ah well, why not check this in. A script to remove all .pyc files in a folder hierarchy.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
28 if __name__ == '__main__': |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
29492
diff
changeset
|
29 main() |
