Rev | Line | |
---|
[3772] | 1 | """Remove computer generated garbage such as |
---|
| 2 | |
---|
| 3 | *.py~ |
---|
| 4 | *.pyc |
---|
| 5 | *.o |
---|
| 6 | *.so |
---|
| 7 | *.dll |
---|
| 8 | |
---|
| 9 | Note: Recompile ANUGA after running this script |
---|
| 10 | """ |
---|
| 11 | |
---|
| 12 | import os |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | extensions_to_delete = ['~', |
---|
| 16 | '.pyc', # Python |
---|
| 17 | '.o', '.so', '.dll', # C |
---|
[4941] | 18 | '.aux', '.ps', # LaTeX |
---|
[5128] | 19 | '.sww', |
---|
| 20 | '.stdout'] |
---|
[5747] | 21 | |
---|
| 22 | |
---|
| 23 | # Data files (may be recovered from repository with svn up) |
---|
| 24 | extensions_to_delete += ['.tms', |
---|
[5757] | 25 | #'.tsh', |
---|
[5747] | 26 | '.msh', |
---|
| 27 | '.pts', |
---|
| 28 | '.xml', |
---|
| 29 | '.png'] |
---|
[3772] | 30 | |
---|
[5747] | 31 | |
---|
[3772] | 32 | filenames_to_delete = [] |
---|
| 33 | for dirpath, dirnames, filenames in os.walk('.'): |
---|
| 34 | |
---|
| 35 | print 'Searching dir', dirpath |
---|
| 36 | |
---|
| 37 | if '.svn' in dirnames: |
---|
| 38 | dirnames.remove('.svn') # don't visit SVN directories |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | for filename in filenames: |
---|
| 42 | for ext in extensions_to_delete: |
---|
| 43 | if filename.endswith(ext): |
---|
| 44 | absname = os.path.join(dirpath, filename) |
---|
| 45 | print ' Flagged for deletion', absname |
---|
| 46 | filenames_to_delete.append(absname) |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | print |
---|
| 50 | N = len(filenames_to_delete) |
---|
| 51 | if N > 0: |
---|
| 52 | msg = '%d files flagged for deletion. Proceed? (Y/N)[N]' %N |
---|
| 53 | answer = raw_input(msg) |
---|
| 54 | |
---|
| 55 | if answer.lower() == 'y': |
---|
| 56 | for filename in filenames_to_delete: |
---|
| 57 | print 'Deleting', filename |
---|
| 58 | os.remove(filename) |
---|
[5747] | 59 | |
---|
| 60 | print 'You may wish to run "svn up" to recover important data files' |
---|
[3772] | 61 | else: |
---|
| 62 | print 'Nothing deleted' |
---|
| 63 | else: |
---|
| 64 | print 'No files flagged for deletion' |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
Note: See
TracBrowser
for help on using the repository browser.