#!/usr/bin/python import os import sys busVector = [ { 'crate' : 'D2:4:42-L', 'bus': 0 }, { 'crate' : 'D2:4:42-L', 'bus': 1 }, { 'crate' : 'D2:4:42-L', 'bus': 2 }, { 'crate' : 'D2:4:42-L', 'bus': 3 }, { 'crate' : 'D2:4:42-R', 'bus': 0 }, { 'crate' : 'D2:4:42-R', 'bus': 1 }, { 'crate' : 'D2:4:42-R', 'bus': 2 }, { 'crate' : 'D2:4:42-R', 'bus': 3 }, { 'crate' : 'D2:4:38-L', 'bus': 0 }, { 'crate' : 'D2:4:38-L', 'bus': 1 }, { 'crate' : 'D2:4:38-L', 'bus': 2 }, { 'crate' : 'D2:4:38-L', 'bus': 3 }, { 'crate' : 'D2:4:38-R', 'bus': 0 }, { 'crate' : 'D2:4:38-R', 'bus': 1 }, { 'crate' : 'D2:4:38-R', 'bus': 2 }, { 'crate' : 'D2:4:38-R', 'bus': 3 }, { 'crate' : 'D2:4:34-L', 'bus': 0 }, { 'crate' : 'D2:4:34-L', 'bus': 1 }, { 'crate' : 'D2:4:34-L', 'bus': 2 }, { 'crate' : 'D2:4:34-L', 'bus': 3 }, { 'crate' : 'D2:4:34-R', 'bus': 0 }, { 'crate' : 'D2:4:34-R', 'bus': 1 }, { 'crate' : 'D2:4:34-R', 'bus': 2 }, { 'crate' : 'D2:4:34-R', 'bus': 3 }, { 'crate' : 'D2:4:30-L', 'bus': 0 }, { 'crate' : 'D2:4:30-L', 'bus': 1 }, { 'crate' : 'D2:4:30-L', 'bus': 2 }, { 'crate' : 'D2:4:30-L', 'bus': 3 }, { 'crate' : 'D2:4:30-R', 'bus': 0 }, { 'crate' : 'D2:4:30-R', 'bus': 1 }, { 'crate' : 'D2:4:30-R', 'bus': 2 }, { 'crate' : 'D2:4:30-R', 'bus': 3 } ] iFile = 1; for bus in busVector[:]: fileName = "fcal-voltage-{0}.cmd".format( iFile ) # print "File name is " , fileName osCommand = "sed -e 's/ANAGATE_NAME/{0}/' ".format( bus['crate'] ) osCommand += " -e 's/BUS_NUMBER/{0}/' ".format( bus['bus'] ) osCommand += " -e 's/\_IOCNUMBER/{0}/' < fcal-voltage-master.cmd > {1}".format( iFile, fileName ) print(osCommand) shellCommand = "csh -c " + "\"" + osCommand + "\"" print(shellCommand) os.system( osCommand ) os.system( "chmod 755 {0}".format( fileName ) ) iFile = iFile + 1 print("Ended")