Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /DQM/Integration/scripts/XMLcfgfiles/updateXMLcfgToCurrentRelease is written in an unsupported language. File is not indexed.

0001 #!/usr/bin/env python3
0002 """Syntax: updateCMLcfgToCurrentRelease [-h] -r relNumber xmlcfgfile newfilename
0003         -h              This text
0004         -r relNumber    tell the script 
0005         xmlcfgfile:     File to update
0006         newfilename:    Name of the file where the changes are going to be saved
0007         
0008 Description: This script will read xmlcfgfile and update it according to the 
0009         environment variables set through cmsenv or its equivalent. The output file 
0010         is written in the current directory; the original file remains unmodified.
0011         
0012 Note: Before you run the script make sure xdaq environment settings have been 
0013         properly set up and that cmsenv or its equivalent has been run from the 
0014         desired release .
0015         
0016 """
0017 import sys, os.path, re
0018 import getopt as gop
0019 
0020 
0021 def detectCMSSWVersion(fileName):
0022         version=""
0023         fp=open(fileName)
0024         line=fp.readline()
0025         total=0
0026         while line:
0027                 if "CMSSW_VERSION=" in line:
0028                         version=line[line.find("CMSSW_VERSION="):line.find(" ",line.find("CMSSW_VERSION="))]
0029                         total+=0x1
0030                 if "CMSSW_BASE=" in line:
0031                         base=line[line.find("CMSSW_BASE="):line.find(" ",line.find("CMSSW_BASE="))]
0032                         total+=0x2
0033                 if "xdaqPath" in line:
0034                         xdaqPath=line[line.find("xdaqPath="):line.find(" ",line.find("xdaqPath="))]
0035                         total+=0x4
0036                 if "pathToExecutive" in line:
0037                         pathToExecutive=line[line.find("pathToExecutive="):line.find(" ",line.find("pathToExecutive="))]
0038                         total+=0x8
0039                 if "SCRAM_ARCH=" in line:
0040                         arch=re.search(r"slc\d_(ia32|amd64)_gcc\d+",line[line.find("SCRAM_ARCH="):line.find(" ",line.find("SCRAM_ARCH="))]).group(0)
0041                         total+=0x10 
0042                 elif "environmentString" in line:
0043                         arch=re.search(r"slc\d_(ia32|amd64)_gcc\d+",line).group(0)
0044                         total+=0x10
0045                 if total == 0x1F:
0046                         break
0047                 line=fp.readline()
0048         fp.close()
0049         version=version.split("=")[1]
0050         base=base.split("=")[1]
0051         xdaqPath=xdaqPath.split("=")[1].strip("\"")
0052         pathToExecutive=pathToExecutive.split("=")[1].split()[0].strip("\"")
0053         return (version,base,xdaqPath,pathToExecutive,arch)
0054 ################################################################################
0055 def updateFile(fileName,newFileName):
0056         import EnviromentSettings as es
0057         oldVersion,oldBase,oldxdaqPath,oldpathToExecutive,oldArch=detectCMSSWVersion(fileName)
0058         oldVersionNumber=oldVersion.split("_",1)[1]
0059         newBase=es.environmentString[es.environmentString.find("CMSSW_BASE="):es.environmentString.find(" ",es.environmentString.find("CMSSW_BASE="))].split("=")[1]
0060         newxdaqPath=es.environmentString[es.environmentString.find("XDAQ_ROOT="):es.environmentString.find(" ",es.environmentString.find("XDAQ_ROOT="))].split("=")[1]
0061         newpathToExecutive="%s/bin/xdaq.sh" % newxdaqPath
0062         newArch=es.environmentString[es.environmentString.find("SCRAM_ARCH="):es.environmentString.find(" ",es.environmentString.find("SCRAM_ARCH="))].split("=")[1]
0063         if not os.path.exists(newpathToExecutive):
0064                 newpathToExecutive="%s/bin/xdaq.exe" % newxdaqPath
0065                 if not os.path.exists(newpathToExecutive):
0066                         sys.stderr.write("\nWARNING: Can't find path to executive: %s\n" % newpathToExecutive ) 
0067         if oldxdaqPath in oldpathToExecutive:
0068                 oldpathToExecutive=oldpathToExecutive.replace(oldxdaqPath,newxdaqPath)
0069         fp=open(fileName)
0070         nfp=open(newFileName,"w")
0071         line=fp.readline()
0072         while line:
0073                 newline=line
0074                 if "environmentString=" in newline:
0075                         envStart=line.find("environmentString=")
0076                         newline=line[0:envStart]
0077                         quote=line[envStart+18:envStart+19]
0078                         newline+="environmentString=\""+es.environmentString
0079                         newline+=line[line.find(quote,envStart+20):]
0080                 if "<Configuration" in newline:
0081                         envStart=line.find("path=")
0082                         newline=line[0:envStart]
0083                         quote=line[envStart+5:envStart+6]
0084                         newline+="path=\""+line[envStart+6:line.rfind("/",envStart+6,line.find(quote,envStart+6))+1]+newFileName.rstrip(".xml")
0085                         newline+=line[line.find(quote,envStart+6):]
0086                 if oldBase in newline:
0087                         newline=newline.replace(oldBase,newBase)
0088                 if oldxdaqPath in newline:
0089                         newline=newline.replace(oldxdaqPath,newxdaqPath)
0090                 if oldpathToExecutive in newline:
0091                         newline=newline.replace(oldpathToExecutive,newpathToExecutive)
0092                 if oldArch in newline:
0093                         newline=newline.replace(oldArch,newArch)
0094                 nfp.write(newline)
0095                 line=fp.readline()
0096                 
0097 
0098 ################################################################################
0099 if __name__ == "__main__":             
0100         try:
0101                 (args,filename)=gop.getopt(sys.argv[1:],"h")
0102         except getopt.GetoptError:
0103                 sys.stderr.write(  "Sintax Error unrecognised option\n" )
0104                 sys.stderr.write( __doc__ )
0105                 sys.exit(2)
0106         for item in args:
0107                 if item[0]=="-h":
0108                         sys.stdout.write( __doc__ )
0109                         sys.exit()
0110         if len(filename)==0:
0111                 sys.stderr.write(  "\nERROR: xdaq XML config file name not present, please specify\n\n" )
0112                 sys.stdout.write(__doc__)
0113         elif len(filename) > 2:
0114                 sys.stderr.write(  "\nERROR: Too many file names or other arguments, please specify only 2\n\n" )
0115                 sys.stdout.write(__doc__)
0116                 sys.exit(2)
0117         elif not os.path.exists(filename[0]):
0118                 sys.stderr.write(  "\nERROR: xdaq XML config file does not exist please verify\n\n" )
0119                 sys.stdout.write(__doc__)
0120                 sys.exit(2)
0121         try: 
0122                 updateFile(filename[0],filename[1])
0123         except IndexError:
0124                 print "Please specify the new file name"