3 __version__ =
"$Revision: 1.11 $"
10 defaultEOSRootPath =
'/eos/cms/store/lhe'
11 defaultEOSLoadPath =
'root://eoscms/'
12 defaultEOSlistCommand =
'xrd eoscms dirlist '
13 defaultEOSmkdirCommand =
'xrd eoscms mkdir '
14 defaultEOSfeCommand =
'xrd eoscms existfile '
15 defaultEOScpCommand =
'xrdcp -np '
19 elements = theDirRecord.split(
' ')
21 return elements[-1].rstrip(
'\n').
split(
'/')[-1]
28 theCommand = defaultEOSlistCommand+
' '+defaultEOSRootPath
29 dirList = subprocess.Popen([
"/bin/sh",
"-c",theCommand], stdout=subprocess.PIPE)
30 for line
in dirList.stdout.readlines():
40 theCommand = defaultEOSlistCommand+
' '+defaultEOSRootPath
41 dirList = subprocess.Popen([
"/bin/sh",
"-c",theCommand], stdout=subprocess.PIPE)
42 for line
in dirList.stdout.readlines():
44 if line.rstrip(
'\n') !=
'':
57 realFileName = f.split(
'/')[-1]
59 newFileName = uploadPath+
'/'+str(realFileName)
62 theCommand = defaultEOSfeCommand+
' '+newFileName
63 exeFullList = subprocess.Popen([
"/bin/sh",
"-c",theCommand], stdout=subprocess.PIPE)
64 result = exeFullList.stdout.readlines()
65 if result[0].rstrip(
'\n') ==
'The file exists.':
67 print 'File '+newFileName+
' already exists: do you want to overwrite? [y/n]'
69 if reply ==
'y' or reply ==
'Y':
71 additionalOption =
' -f '
73 print 'Overwriting file '+newFileName+
'\n'
76 print 'Adding file '+str(f)+
'\n'
77 inUploadScript += defaultEOScpCommand+additionalOption+
' '+str(f)+
' '+defaultEOSLoadPath+uploadPath+
'/'+str(realFileName)+
'\n'
81 print '\n Launching upload script \n'+inUploadScript+
'\n at '+time.asctime(time.localtime(time.time()))+
' ...\n'
83 exeRealUpload = subprocess.Popen([
"/bin/sh",
"-c",inUploadScript])
84 exeRealUpload.communicate()
85 print '\n Upload ended at '+time.asctime(time.localtime(time.time()))
89 if __name__ ==
'__main__':
94 usage=
'cmsLHEtoEOSManager.py <options>'
95 parser = optparse.OptionParser(usage)
96 parser.add_option(
'-f',
'--file',
97 help=
'LHE local file list to be uploaded, separated by ","' ,
101 parser.add_option(
'-n',
'--new',
102 help=
'Create a new article' ,
107 parser.add_option(
'-u',
'--update',
108 help=
'Update the article <Id>' ,
112 parser.add_option(
'-l',
'--list',
113 help=
'List the files in article <Id>' ,
117 parser.add_option(
'-d',
'--dry-run',
118 help=
'dry run, it does nothing, but you can see what it would do',
123 parser.add_option(
'-c',
'--compress',
124 help=
'compress the local .lhe file with xc before upload',
129 (options,args) = parser.parse_args()
134 print 'cmsLHEtoEOSmanager '+__version__[1:-1]
136 print 'Running on ',time.asctime(time.localtime(time.time()))
139 reallyDoIt =
not options.dryRun
142 if not options.newId
and options.artIdUp==0
and options.artIdLi==0:
143 raise Exception(
'Please specify the action to be taken, either "-n", "-u" or "-l"!')
145 if options.fileList==
'' and (options.newId
or options.artIdUp!=0):
146 raise Exception(
'Please provide the input file list!')
148 if (options.newId
and (options.artIdUp != 0
or options.artIdLi != 0))
or (options.artIdUp != 0
and options.artIdLi != 0):
149 raise Exception(
'Options "-n", "-u" and "-l" are mutually exclusive, please chose only one!')
152 print 'Action: create new article\n'
153 elif options.artIdUp != 0:
154 print 'Action: update article '+str(options.artIdUp)+
'\n'
155 elif options.artIdLi != 0:
156 print 'Action: list content of article '+str(options.artIdLi)+
'\n'
158 if options.artIdLi==0:
159 theList = options.fileList.split(
',')
160 theCompressedFilesList = []
163 if not ( f.lower().endswith(
".lhe")
or f.lower().endswith(
".lhe.xz") ):
164 raise Exception(
'Input file name must have the "lhe" or "lhe.xz" final extension!')
166 if not os.path.exists(f):
167 raise Exception(
'Input file '+f+
' does not exists')
168 if reallyDoIt
and options.compress:
169 print "Compressing file",f
170 theCompressionCommand =
'xz '+f
171 exeCompression = subprocess.Popen([
"/bin/sh",
"-c",theCompressionCommand])
172 exeCompression.communicate()
173 theCompressedFilesList.append(f+
'.xz')
174 if reallyDoIt
and options.compress:
175 theList = theCompressedFilesList
187 print 'Creating new article with identifier '+str(newArt)+
' ...\n'
188 uploadPath = defaultEOSRootPath+
'/'+str(newArt)
189 theCommand = defaultEOSmkdirCommand+
' '+uploadPath
191 exeUpload = subprocess.Popen([
"/bin/sh",
"-c",theCommand])
192 exeUpload.communicate()
196 elif options.artIdUp != 0:
197 newArt = options.artIdUp
199 uploadPath = defaultEOSRootPath+
'/'+str(newArt)
201 raise(
'Article '+str(newArt)+
' to be updated does not exist!')
205 elif options.artIdLi !=0:
206 listPath = defaultEOSRootPath+
'/'+str(options.artIdLi)
207 theCommand = defaultEOSlistCommand+
' '+listPath
208 exeList = subprocess.Popen([
"/bin/sh",
"-c",theCommand], stdout=subprocess.PIPE)
209 for line
in exeList.stdout.readlines():
216 listPath = defaultEOSRootPath+
'/'+str(newArt)
218 print 'Listing the '+str(newArt)+
' article content after upload:'
219 theCommand = defaultEOSlistCommand+
' '+listPath
221 exeFullList = subprocess.Popen([
"/bin/sh",
"-c",theCommand])
222 exeFullList.communicate()
224 print 'Dry run, nothing was done'
const T & max(const T &a, const T &b)