forked from cms-sw/pkgtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmsMakeMELists.py
executable file
·68 lines (59 loc) · 1.99 KB
/
cmsMakeMELists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
#
# June 21, 2008
# dlange, LLNL
#
# Simple script to regenerate ME directory listings
#
# Output is series of files in baseDir (defined below)
import md5
import os
from os.path import join, getsize
baseDir='/data/generatorData'
baseDirWeb='http://cmsrep.cern.ch/cmssw/ME/'
listFileEnding='list'
contents={}
mydirs={}
# find all files except for our list files
# under the baseDir
for root, dirs, files in os.walk(baseDir):
if ( root.find('save')==-1):
for file in files:
if ( root != baseDir):
mysum=md5.md5(open(root+'/'+file).read()).hexdigest()
contents[root+':'+file]=mysum
mydirs[root]=1
else:
if ( file.split('.')[-1] == listFileEnding ):
if ( not os.path.exists(baseDir+'/save')):
os.mkdir(baseDir+'/save')
os.rename(root+'/'+file,root+'/save/'+file)
# Ok, now for each directly with a file, write out a list file
#-ap: as the version dir may contain subdirs (e.g. sherpa/7TeV/EXO/1.2.1-cms/...)
# first move the existing list files to a backup :
import glob
listFiles = glob.glob('slc*.list')
for lf in listFiles:
print 'backing up ', lf
os.rename(lf, lf+'-bkp')
for dir in mydirs:
webDirSP=dir.split('/')[3:]
if ( len(webDirSP)<6):
continue
webloc=baseDirWeb
for w in webDirSP:
webloc=webloc+w+'/'
#magic -- <arch>_<generator>_<energy>_<subdir>_<version>
outFile=baseDir+'/'+webDirSP[0]+':'+webDirSP[2]+':'+webDirSP[3]+':'+webDirSP[4]+':'+webDirSP[5]+'.'+listFileEnding
#-ap: now first check if the file was already opened, if so, append:
if os.path.exists(outFile):
fout=open(outFile,'a')
else:
fout=open(outFile,'w')
for entry in contents:
eDir=entry.split(':')[0]
eFile=entry.split(':')[1]
if ( eDir == dir ):
webFile=webloc+eFile
fout.write(webFile + ' ' + contents[entry]+'\n')
fout.close()