1
2
3
4 """
5 Edits a specific keyword in all files in a certain filter in a
6 recalibration log by a correction term.
7
8 @author: N.J. Cross
9 @org: WFAU, IfA, University of Edinburgh
10 """
11
12 import os
13 import sys
14
15 from wsatools.DbConnect.DbSession import DbSession
16
17
18
19
20 if __name__ == '__main__':
21 logFilePath=sys.argv[1]
22 filterID=int(sys.argv[2])
23 keywordName=sys.argv[3]
24 correction=float(sys.argv[4])
25 db=DbSession()
26 catalogues=db.query(selectStr="catName",
27 fromStr="Multiframe",
28 whereStr="frameType like '%stack' and deprecated<128 "
29 +"and filterID=%d" % filterID)
30 del db
31 outLogFilePath=os.path.basename(logFilePath.split('.')[0]+'_update.log')
32 lines=file(logFilePath).readlines()
33
34 catFileDict={}
35 for index,line in enumerate(lines):
36 wrds=line.split()
37 if wrds[0][:4]=="w200" and wrds[1]=="#1":
38 catFileDict[wrds[0]]=index
39 newLines=[]
40 for catName in catalogues:
41 prtName=os.path.basename(catName)
42 try:
43 index=catFileDict[prtName]
44 except:
45 continue
46 test=False
47
48 while not test:
49 if lines[index][0]=="w" and lines[index].split()[0]!=prtName:
50 test=True
51 elif lines[index][0]!="w" and lines[index].split()[0]!="HISTORY":
52 wrds=lines[index].split("=")
53 if wrds[0]==keywordName:
54 value,comment=wrds[1].split("/")
55 value=float(value)+correction
56 newline="%s=\t\t%5.2f / %s" % (keywordName,value,comment)
57 newLines.append(newline)
58 else:
59 newLines.append(lines[index])
60 else:
61 newLines.append(lines[index])
62
63 index+=1
64 if index==len(lines):
65 test=True
66 file(outLogFilePath,'w').writelines(newLines)
67
68
69
70
71
72
73
74