1 | #!/usr/bin/env python |
---|
2 | """ |
---|
3 | Renames a dataset file by appending _purged to the file name so that it can later be removed from disk. |
---|
4 | Usage: python rename_purged_datasets.py purge.log |
---|
5 | """ |
---|
6 | |
---|
7 | import sys, os |
---|
8 | |
---|
9 | assert sys.version_info[:2] >= ( 2, 4 ) |
---|
10 | |
---|
11 | def main(): |
---|
12 | infile = sys.argv[1] |
---|
13 | outfile = infile + ".renamed.log" |
---|
14 | out = open( outfile, 'w' ) |
---|
15 | |
---|
16 | print >> out, "# The following renamed datasets can be removed from disk" |
---|
17 | i = 0 |
---|
18 | renamed_files = 0 |
---|
19 | for i, line in enumerate( open( infile ) ): |
---|
20 | line = line.rstrip( '\r\n' ) |
---|
21 | if line and line.startswith( '/var/opt/galaxy' ): |
---|
22 | try: |
---|
23 | purged_filename = line + "_purged" |
---|
24 | os.rename( line, purged_filename ) |
---|
25 | print >> out, purged_filename |
---|
26 | renamed_files += 1 |
---|
27 | except Exception, exc: |
---|
28 | print >> out, "# Error, exception " + str( exc ) + " caught attempting to rename " + purged_filename |
---|
29 | print >> out, "# Renamed " + str( renamed_files ) + " files" |
---|
30 | |
---|
31 | if __name__ == "__main__": |
---|
32 | main() |
---|