3 __version__ =
"$Revision: 1.12 $"
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') !=
'':
52 def fileUpload(uploadPath,lheList, checkSumList, reallyDoIt):
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'
77 inUploadScript = defaultEOScpCommand + additionalOption +
' ' + str(f) +
' ' + defaultEOSLoadPath+uploadPath +
'/' + str(realFileName)
78 print 'Uploading file %s...' % str(f)
80 exeRealUpload = subprocess.Popen([
"/bin/sh",
"-c",inUploadScript])
81 exeRealUpload.communicate()
82 eosCheckSumCommand =
'/afs/cern.ch/project/eos/installation/0.3.15/bin/eos.select find --checksum ' + uploadPath +
'/' + str(realFileName) +
' | awk \'{print $2}\' | cut -d= -f2'
83 exeEosCheckSum = subprocess.Popen(eosCheckSumCommand ,shell=
True, stdout=subprocess.PIPE)
84 EosCheckSum = exeEosCheckSum.stdout.read()
85 assert exeEosCheckSum.wait() == 0
86 print 'checksum: eos = ' + EosCheckSum +
'orig file = ' + checkSumList[index] +
'\n'
87 if checkSumList[index]
not in EosCheckSum:
88 print 'WARNING! The checksum for file ' + str(realFileName) +
' in EOS\n'
89 print EosCheckSum +
'\n'
90 print 'does not match the checksum of the original one\n'
91 print checkSumList[index] +
'\n'
92 print 'please try to re-upload file ' + str(realFileName) +
' to EOS.\n'
101 print '\n Upload ended at '+time.asctime(time.localtime(time.time()))
105 if __name__ ==
'__main__':
110 usage=
'cmsLHEtoEOSManager.py <options>'
111 parser = optparse.OptionParser(usage)
112 parser.add_option(
'-f',
'--file',
113 help=
'LHE local file list to be uploaded, separated by ","' ,
117 parser.add_option(
'-F',
'--files-from', metavar =
'FILE',
118 help=
'File containing the list of LHE local files be uploaded, one file per line')
120 parser.add_option(
'-n',
'--new',
121 help=
'Create a new article' ,
126 parser.add_option(
'-u',
'--update',
127 help=
'Update the article <Id>' ,
131 parser.add_option(
'-l',
'--list',
132 help=
'List the files in article <Id>' ,
136 parser.add_option(
'-d',
'--dry-run',
137 help=
'dry run, it does nothing, but you can see what it would do',
142 parser.add_option(
'-c',
'--compress',
143 help=
'compress the local .lhe file with xz before upload',
148 (options,args) = parser.parse_args()
153 print 'cmsLHEtoEOSmanager '+__version__[1:-1]
155 print 'Running on ',time.asctime(time.localtime(time.time()))
158 reallyDoIt =
not options.dryRun
161 if not options.newId
and options.artIdUp==0
and options.artIdLi==0:
162 raise Exception(
'Please specify the action to be taken, either "-n", "-u" or "-l"!')
164 if options.fileList ==
'' and not options.files_from
and (options.newId
or options.artIdUp!=0):
165 raise Exception(
'Please provide the input file list!')
167 if (options.newId
and (options.artIdUp != 0
or options.artIdLi != 0))
or (options.artIdUp != 0
and options.artIdLi != 0):
168 raise Exception(
'Options "-n", "-u" and "-l" are mutually exclusive, please choose only one!')
171 print 'Action: create new article\n'
172 elif options.artIdUp != 0:
173 print 'Action: update article '+str(options.artIdUp)+
'\n'
174 elif options.artIdLi != 0:
175 print 'Action: list content of article '+str(options.artIdLi)+
'\n'
177 if options.artIdLi==0:
179 if len(options.fileList) > 0:
180 theList=(options.fileList.split(
','))
182 if options.files_from:
184 f = open(options.files_from)
186 raise Exception(
'Cannot open the file list, \'%s\'' % options.files_from)
189 if len(l) == 0
or l[0] ==
'#':
193 theCompressedFilesList = []
198 if not ( f.lower().endswith(
".lhe")
or f.lower().endswith(
".lhe.xz") ):
199 raise Exception(
'Input file name must have the "lhe" or "lhe.xz" final extension!')
200 if( f.lower().endswith(
".lhe.xz") ):
201 print "Important! Input file "+f+
" is already zipped: please make sure you verified its integrity with xmllint before zipping it. You can do it with:\n"
202 print "xmllint file.lhe\n"
203 print "Otherwise it is best to pass the unzipped file to this script and let it check its integrity and compress the file with the --compress option\n"
204 exeCheckSum = subprocess.Popen([
"/afs/cern.ch/cms/caf/bin/cms_adler32",f], stdout=subprocess.PIPE)
205 getCheckSum = subprocess.Popen([
"awk",
"{print $1}"], stdin=exeCheckSum.stdout, stdout=subprocess.PIPE)
206 exeCheckSum.stdout.close()
207 output,err = getCheckSum.communicate()
208 print 'orig file checksum = ' + output +
'\n'
209 theCheckSumList.append(output)
211 if not os.path.exists(f):
212 raise Exception(
'Input file '+f+
' does not exists')
213 if( f.lower().endswith(
".lhe") ):
214 theCheckIntegrityCommand =
'xmllint -noout '+f
215 exeCheckIntegrity = subprocess.Popen([
"/bin/sh",
"-c", theCheckIntegrityCommand])
216 intCode = exeCheckIntegrity.wait()
217 if(intCode
is not 0):
218 raise Exception(
'Input file '+f+
' is corrupted')
219 if reallyDoIt
and options.compress:
220 print "Compressing file",f
221 if( f.lower().endswith(
".lhe.xz") ):
222 raise Exception(
'Input file '+f+
' is already compressed! This is inconsistent with the --compress option!')
223 theCompressionCommand =
'xz '+f
224 exeCompression = subprocess.Popen([
"/bin/sh",
"-c",theCompressionCommand])
225 exeCompression.communicate()
226 exeCheckSum = subprocess.Popen([
"/afs/cern.ch/cms/caf/bin/cms_adler32",f+
".xz"], stdout=subprocess.PIPE)
227 getCheckSum = subprocess.Popen([
"awk",
"{print $1}"], stdin=exeCheckSum.stdout, stdout=subprocess.PIPE)
228 exeCheckSum.stdout.close()
229 output,err = getCheckSum.communicate()
230 print 'orig file checksum = ' + output +
'\n'
231 theCheckSumList.append(output)
232 theCompressedFilesList.append(f+
'.xz')
233 if reallyDoIt
and options.compress:
234 theList = theCompressedFilesList
244 print 'Creating new article with identifier '+str(newArt)+
' ...\n'
245 uploadPath = defaultEOSRootPath+
'/'+str(newArt)
246 theCommand = defaultEOSmkdirCommand+
' '+uploadPath
248 exeUpload = subprocess.Popen([
"/bin/sh",
"-c",theCommand])
249 exeUpload.communicate()
253 elif options.artIdUp != 0:
254 newArt = options.artIdUp
256 uploadPath = defaultEOSRootPath+
'/'+str(newArt)
258 raise Exception(
'Article '+str(newArt)+
' to be updated does not exist!')
262 elif options.artIdLi !=0:
263 listPath = defaultEOSRootPath+
'/'+str(options.artIdLi)
264 theCommand = defaultEOSlistCommand+
' '+listPath
265 exeList = subprocess.Popen([
"/bin/sh",
"-c",theCommand], stdout=subprocess.PIPE)
266 for line
in exeList.stdout.readlines():
272 fileUpload(uploadPath,theList, theCheckSumList, reallyDoIt)
273 listPath = defaultEOSRootPath+
'/'+str(newArt)
275 print 'Listing the '+str(newArt)+
' article content after upload:'
276 theCommand = defaultEOSlistCommand+
' '+listPath
278 exeFullList = subprocess.Popen([
"/bin/sh",
"-c",theCommand])
279 exeFullList.communicate()
281 print 'Dry run, nothing was done'
if(conf.exists("allCellsPositionCalc"))