| Last change
 on this file since 392 was             391, checked in by dmik, 12 years ago | 
        
          | 
python: Merge vendor 2.7.6 to trunk.
 | 
        
          | 
              
Property                 svn:eol-style
 set to                 native | 
        
          | File size:
            658 bytes | 
      
      
| Line |  | 
|---|
| 1 | #!/usr/bin/env python | 
|---|
| 2 | """Recursively zap all .pyc and .pyo files""" | 
|---|
| 3 | import os | 
|---|
| 4 | import sys | 
|---|
| 5 |  | 
|---|
| 6 | # set doit true to actually delete files | 
|---|
| 7 | # set doit false to just print what would be deleted | 
|---|
| 8 | doit = 1 | 
|---|
| 9 |  | 
|---|
| 10 | def main(): | 
|---|
| 11 | if not sys.argv[1:]: | 
|---|
| 12 | print 'Usage: zappyc dir ...' | 
|---|
| 13 | sys.exit(1) | 
|---|
| 14 | for dir in sys.argv[1:]: | 
|---|
| 15 | zappyc(dir) | 
|---|
| 16 |  | 
|---|
| 17 | def zappyc(dir): | 
|---|
| 18 | os.path.walk(dir, walker, None) | 
|---|
| 19 |  | 
|---|
| 20 | def walker(dummy, top, names): | 
|---|
| 21 | for name in names: | 
|---|
| 22 | if name[-4:] in ('.pyc', '.pyo'): | 
|---|
| 23 | path = os.path.join(top, name) | 
|---|
| 24 | print 'Zapping', path | 
|---|
| 25 | if doit: | 
|---|
| 26 | os.unlink(path) | 
|---|
| 27 |  | 
|---|
| 28 | if __name__ == '__main__': | 
|---|
| 29 | main() | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.