PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/scripts/cleanup_datasets/rename_purged_datasets.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 32 lines | 22 code | 5 blank | 5 comment | 5 complexity | 19e4f63d7d6f1ed10f590fc8b704f319 MD5 | raw file
 1#!/usr/bin/env python
 2"""
 3Renames a dataset file by appending _purged to the file name so that it can later be removed from disk.
 4Usage: python rename_purged_datasets.py purge.log
 5"""
 6
 7import sys, os
 8
 9assert sys.version_info[:2] >= ( 2, 4 )
10
11def 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
31if __name__ == "__main__":
32    main()