ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/dhidas/OSUAnalysis/Tools/scripts/deleteGridFolder
Revision: 1.1.1.1 (vendor branch)
Committed: Thu Dec 1 16:28:48 2011 UTC (13 years, 5 months ago) by dhidas
Branch: dhidas, MAIN
CVS Tags: START, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
osu copy modified

File Contents

# User Rev Content
1 dhidas 1.1 #!/usr/bin/env python
2     '''
3     Created on 7 Jun 2010
4    
5     @author: kreczko
6    
7     Email: kreczko@cern.ch
8     '''
9     import sys
10     try:
11     import subprocess
12     except:
13     print "You have to use Python 2.4 or higher"
14     sys.exit(0)
15     from optparse import OptionParser
16     files = []
17     directories = []
18    
19     srmBase = 'srm://lcgse02.phy.bris.ac.uk:8444/srm/managerv2?SFN='
20    
21     def getFiles(gridFolder, input):
22     if gridFolder.endswith('/'):
23     gridFolder = gridFolder.rstrip('/')
24     input = input.rstrip(' ')
25     fileLinesOnly = input[input.find(gridFolder)+len(gridFolder):]
26     fileLines = fileLinesOnly.split('\n')[1:]
27     fileLines = [fileLine.lstrip(' ') for fileLine in fileLines]
28     files = [line.split(' ')[1] for line in fileLines if len(line.split(' ')) == 2]
29     files.sort()
30     return files
31    
32     def listFiles(gridFolder):
33     output = subprocess.Popen(['srmls', srmBase + gridFolder], stdout = subprocess.PIPE).communicate()[0]
34     return output
35    
36     def delete(file):
37     output = subprocess.Popen(['srmrm', srmBase + file], stdout = subprocess.PIPE).communicate()[0]
38     return output
39    
40     def deleteFolder(folder):
41     output = subprocess.Popen(['srmrmdir', srmBase + folder], stdout = subprocess.PIPE).communicate()[0]
42     return output
43    
44     def deleteGridFolder(path):
45     filelist = listFiles(path)
46     for file in getFiles(path, filelist):
47     delete(file)
48     deleteFolder(path)
49    
50     if __name__ == '__main__':
51    
52     parser = OptionParser()
53     parser.add_option("-r", "--recursive",
54     action="store_true", dest="recursive", default=False,
55     help="delete grid folder recursively")
56    
57     (options, args) = parser.parse_args()
58     if len(args) >0 and not options['recursive']:
59     path = args[0]
60     deleteGridFolder(path)
61     elif len(args) >0 and options['recursive']:
62     pass
63    
64     else:
65     print 'Delete path was not specified. Use script "./deleteGridFolder path"'