CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/PKGTOOLS/cmsMakeMELists.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 #
00004 # June 21, 2008
00005 # dlange, LLNL
00006 #
00007 # Simple script to regenerate ME directory listings
00008 #
00009 # Output is series of files in baseDir (defined below)
00010 import md5
00011 import os
00012 from os.path import join, getsize
00013 
00014 
00015 baseDir='/data/generatorData'
00016 baseDirWeb='https://cmsrep.cern.ch/cmssw/ME/'
00017 listFileEnding='list'
00018 contents={}
00019 mydirs={}
00020 
00021 # find all files except for our list files
00022 # under the baseDir
00023 
00024 for root, dirs, files in os.walk(baseDir):
00025     if ( root.find('save')==-1):
00026         for file in files:
00027             if ( root != baseDir):
00028                 mysum=md5.md5(open(root+'/'+file).read()).hexdigest()
00029                 contents[root+':'+file]=mysum
00030                 mydirs[root]=1
00031             else:
00032                 if ( file.split('.')[-1] == listFileEnding ):
00033                     if ( not os.path.exists(baseDir+'/save')):
00034                         os.mkdir(baseDir+'/save')
00035                     os.rename(root+'/'+file,root+'/save/'+file)
00036 
00037 # Ok, now for each directly with a file, write out a list file
00038 
00039 #-ap: as the version dir may contain subdirs (e.g. sherpa/7TeV/EXO/1.2.1-cms/...)
00040 # first move the existing list files to a backup :
00041 import glob
00042 listFiles = glob.glob('slc*.list')
00043 for lf in listFiles:
00044     print 'backing up ', lf
00045     os.rename(lf, lf+'-bkp')
00046 
00047 for dir in mydirs:
00048     webDirSP=dir.split('/')[3:]
00049     if ( len(webDirSP)<6):
00050         continue
00051     webloc=baseDirWeb
00052     for w in webDirSP:
00053         webloc=webloc+w+'/'
00054 #magic -- <arch>_<generator>_<energy>_<subdir>_<version>
00055     outFile=baseDir+'/'+webDirSP[0]+':'+webDirSP[2]+':'+webDirSP[3]+':'+webDirSP[4]+':'+webDirSP[5]+'.'+listFileEnding
00056 
00057     #-ap: now first check if the file was already opened, if so, append:
00058     if os.path.exists(outFile):
00059         fout=open(outFile,'a')
00060     else:
00061         fout=open(outFile,'w')
00062     for entry in contents:
00063         eDir=entry.split(':')[0]
00064         eFile=entry.split(':')[1]
00065         if ( eDir == dir ):
00066             webFile=webloc+eFile    
00067             fout.write(webFile + ' ' + contents[entry]+'\n')
00068     fout.close()