1 | #!/usr/bin/env python |
---|
2 | """ |
---|
3 | Removes a dataset file ( which was first renamed by appending _purged to the file name ) from disk. |
---|
4 | Usage: python remove_renamed_datasets_from_disk.py renamed.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 + ".removed.log" |
---|
14 | out = open( outfile, 'w' ) |
---|
15 | |
---|
16 | print >> out, "# The following renamed datasets have been removed from disk" |
---|
17 | i = 0 |
---|
18 | removed_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 | os.unlink( line ) |
---|
24 | print >> out, line |
---|
25 | removed_files += 1 |
---|
26 | except Exception, exc: |
---|
27 | print >> out, "# Error, exception " + str( exc ) + " caught attempting to remove " + line |
---|
28 | print >> out, "# Removed " + str( removed_files ) + " files" |
---|
29 | |
---|
30 | if __name__ == "__main__": |
---|
31 | main() |
---|