ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/ForwardAnalysis/Scripts/scripts/copyFilesFromEOS.py
Revision: 1.1
Committed: Fri Jul 20 18:22:52 2012 UTC (12 years, 9 months ago) by antoniov
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Log Message:
update

File Contents

# User Rev Content
1 antoniov 1.1 #! /usr/bin/env python
2    
3     import sys
4     import optparse
5     from subprocess import Popen,PIPE,call
6     from listFilesEOS import listFilesEOS
7    
8     def copyFilesFromEOS(dir,output_dir,type,suffix,enable):
9    
10     cpcmd = 'xrdcp'
11     copy_prefix = 'root://eoscms//eos/cms'
12    
13     files = listFilesEOS(dir,type,copy_prefix)
14     if suffix: files = [item + suffix for item in files]
15    
16     print "Copying from %s to %s" % (dir,output_dir)
17     for item in files:
18     cmd = '%s %s %s' % (cpcmd,item,output_dir)
19     print cmd
20     if enable:
21     retcode = call(cmd,shell=True)
22     if retcode != 0: raise RuntimeError,'Error in copying file %s to directory %s' % (item,output_dir)
23    
24     if __name__ == '__main__':
25     parser = optparse.OptionParser(usage="usage: %prog [options]")
26     parser.add_option("-o","--out", dest="out", metavar="OUT", help="output directory")
27     parser.add_option("-d","--dir", dest="dir", metavar="DIR", help="copy files from DIR")
28     parser.add_option("-t","--type", dest="type", default="root", metavar="TYPE", help="select only files with substring TYPE (Default: 'root')")
29     #parser.add_option("-p","--prefix", dest="prefix", default="", metavar="PREFIX", help="prepend PREFIX to file path")
30     parser.add_option("-s","--suffix", dest="suffix", default="", metavar="SUFFIX", help="append SUFFIX to file path")
31     parser.add_option("--no_exec", dest="enable", action="store_false", default=True, help="files will not be copied")
32    
33     (input, args) = parser.parse_args()
34    
35     if not input.dir: parser.error('must set input directory')
36     if not input.out: parser.error('must set output directory')
37    
38     copyFilesFromEOS(dir = input.dir,
39     output_dir = input.out,
40     type = input.type,
41     #prefix = input.prefix,
42     suffix = input.suffix,
43     enable = input.enable)
44    
45     sys.exit(0)