00001
00002
00003 class BesTofDatSvc:
00004 def __init__(self):
00005 import os
00006 self.__rootPath = os.getenv('TOFSIMROOT') + '/dat/'
00007
00008 self.__file = open(self.__rootPath + 'srcBesTof.txt', 'r')
00009 self.__fileLines = self.__file.readlines()
00010 self.__file.close()
00011
00012 def do(self, key, value):
00013 oldLines = self.__fileLines
00014 upperKey = key.upper()
00015 lineNo = 0
00016 wantLine = 0
00017 wantWord = 0
00018
00019 for eachLine in oldLines:
00020 upperLine = eachLine.upper()
00021 allWords = upperLine.split()
00022 wordNo = 0
00023 flag = 0
00024
00025 for eachWord in allWords:
00026 if eachWord == upperKey:
00027 wantLine = lineNo + 1
00028 wantWord = wordNo
00029 flag = 1
00030 break
00031 wordNo = wordNo + 1
00032
00033 if flag == 1:
00034 break
00035 lineNo = lineNo + 1
00036
00037 oldValues = oldLines[wantLine].split()
00038
00039 newValues = []
00040 for i in xrange(oldValues.__len__()):
00041 if i == wantWord:
00042 newValues.append(value)
00043 else:
00044 newValues.append(oldValues[i])
00045 newLine = ' '.join(newValues)
00046 newLine = newLine + '\n'
00047
00048 self.__fileLines = []
00049 for i in xrange(oldLines.__len__()):
00050 if i == wantLine:
00051 self.__fileLines.append(newLine)
00052 else:
00053 self.__fileLines.append(oldLines[i])
00054
00055 def write(self):
00056 outFile = open(self.__rootPath + 'BesTof.txt', 'w')
00057 outFile.writelines(self.__fileLines)
00058 outFile.close()
00059
00060
00061 if __name__ == '__main__':
00062 besTofDatSvc = BesTofDatSvc()
00063 besTofDatSvc.do('atten', '3900')
00064 besTofDatSvc.do('phNConst', '8000')
00065 besTofDatSvc.write()