ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/ForwardAnalysis/Scripts/scripts/copyFilesFromSE.py
Revision: 1.1
Committed: Fri Sep 16 17:07:48 2011 UTC (13 years, 7 months ago) by antoniov
Content type: text/x-python
Branch: MAIN
CVS Tags: antoniov-forwardAnalysis-Oct072011-v1, sfonseca_10_04_2011, antoniov-forwardAnalysis-Sep182011-v1, HEAD
Log Message:
update

File Contents

# User Rev Content
1 antoniov 1.1 #!/usr/bin/python
2    
3     import os,sys
4    
5     if __name__ == '__main__':
6     import optparse
7     usage = "usage: %prog [options] <remote dir> <local dir>"
8     parser = optparse.OptionParser(usage=usage)
9     parser.add_option("-s","--site", dest="site", metavar="SITE", help="site name")
10     parser.add_option("-p","--port", dest="port", type="int", default=8443, metavar="PORT", help="SRM port (Default: 8443)")
11     parser.add_option("-t","--type", dest="type", default="root", metavar="TYPE", help="select only files with substring TYPE (Default: 'root')")
12     parser.add_option("--srm_str", dest="srmstr", default="/srm/v2/server?SFN=", metavar="SRM", help="SRM string (Default: '/srm/v2/server?SFN=')")
13     parser.add_option("--no_exec", dest="enable", action="store_false", default=True, help="files will not be copied")
14    
15     (input, args) = parser.parse_args()
16    
17     if not input.site: parser.error('must set site name')
18     if len(args) != 2: parser.error('exactly two arguments required')
19    
20     from subprocess import Popen,PIPE,call
21     lscmd = 'lcg-ls -b -D srmv2 --vo cms'
22     cpcmd = 'lcg-cp -b -D srmv2 --vo cms'
23    
24     #srm_string = '//srm/managerv2?SFN='
25     #srm_string = '/srm/v2/server?SFN='
26     srm_string = input.srmstr
27     storage_name = input.site
28     storage_port = input.port
29     storage_path = args[0]
30     outdir = args[1]
31     type = input.type
32     endpoint = 'srm://' + storage_name + ':' + str(storage_port) + srm_string
33     fullpath = endpoint + storage_path
34     lscmd = '%s "%s"' % (lscmd,fullpath)
35     print lscmd
36     p1 = Popen(lscmd,shell=True,stdout=PIPE)
37     files = [item.rstrip().split("/")[-1] for item in p1.stdout if item.find(type) != -1]
38     for file in files:
39     outfile = os.path.abspath(outdir) + "/" + file
40     cmd = '%s "%s/%s" "file:%s"' % (cpcmd,fullpath,file,outfile)
41     print cmd
42     if input.enable: call(cmd,shell=True)