Changeset 31201 for trunk/ippToPsps/jython/batch.py
- Timestamp:
- Apr 6, 2011, 1:07:09 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/batch.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/batch.py
r31183 r31201 5 5 import re 6 6 import sys 7 import os 8 import md5 7 9 8 10 from gpc1db import Gpc1Db 11 from ipptopspsdb import IppToPspsDb 9 12 10 13 from java.lang import * 11 14 from java.sql import * 12 from xml.etree.ElementTree import ElementTree 13 15 from xml.etree.ElementTree import ElementTree, Element, tostring 16 from xml.dom import minidom 14 17 15 18 ''' … … 30 33 31 34 # set up class variables 35 self.batchType = batchType; 32 36 self.pspsVoTableFilePath = "../config/" + batchType + "/tables.vot" 33 37 self.inputFitsPath = inputFitsPath … … 46 50 self.localStmt = self.localCon.createStatement() 47 51 48 # create Gpc1 object52 # create Gpc1Db object 49 53 self.gpc1Db = Gpc1Db() 50 51 # set up JDBC connection to gpc1 Db52 dbName = doc.find("gpc1database/name").text53 dbHost = doc.find("gpc1database/host").text54 dbUser = doc.find("gpc1database/user").text55 dbPass = doc.find("gpc1database/password").text56 self.gpc1Url = "jdbc:mysql://"+dbHost+"/"+dbName+"?user="+dbUser+"&password="+dbPass57 self.gpc1Con = DriverManager.getConnection(self.localUrl)58 self.gpc1Stmt = self.localCon.createStatement()59 54 60 55 # get survey ID from init table … … 67 62 self.log("No survey ID found for this survey: '" + survey + "'") 68 63 self.surveyID = -1; 69 64 65 # get dvo info from config 66 dvoName = doc.find(survey+"dvo/name").text 67 dvoLocation = doc.find(survey+"dvo/location").text 68 69 # get datastore info from config 70 datastoreProduct = doc.find("datastore/product").text 71 72 # create IppToPspsDb object and create a new batch 73 self.ippToPspsDb = IppToPspsDb() 74 self.batchID = self.ippToPspsDb.createNewBatch(66, survey, self.getPspsBatchType(), dvoName, datastoreProduct) 75 76 # get local storage location from config 77 self.batchName = "B%08d" % self.batchID 78 self.localOutPath = doc.find("localOutPath").text + "/" + self.getPspsBatchType() + "/" + dvoName + "/%s" % self.batchName 79 if not os.path.exists(self.localOutPath): os.makedirs(self.localOutPath) 80 81 70 82 # store today's date 71 83 now = datetime.datetime.now(); 72 84 self.dateStr = now.strftime("%Y-%m-%d") 73 85 74 if self.inputFitsPath != "": 75 self.parseFitsHeader() 86 if self.inputFitsPath != "": self.parseFitsHeader() 87 88 # create DVO table 89 self.createDvoTable() 76 90 77 91 ''' … … 83 97 self.localStmt.close() 84 98 self.localCon.close() 85 self.gpc1Stmt.close() 86 self.gpc1Con.close() 99 100 ''' 101 Writes the batch manifest file 102 ''' 103 def writeBatchManifest(self): 104 105 outPath = self.localOutPath + "/BatchManifest.xml" 106 tmpPath = "./tmp.xml" 107 self.log("Creating batch manifest file here: " + outPath) 108 root = Element('manifest') 109 110 # batch information 111 root.attrib['name'] = self.batchName 112 root.attrib['type'] = self.getPspsBatchType() 113 root.attrib['survey'] = self.getPspsSurveyType() 114 root.attrib['timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 115 root.attrib['minObjId'] = str(self.minObjID) 116 root.attrib['maxObjId'] = str(self.maxObjID) 117 118 # get md5sum 119 fits=os.popen("md5sum " + self.outputFitsPath) 120 for f in fits.readlines(): md5sum = f[0:f.rfind(" ")] 121 122 # get file size 123 fileSize = os.path.getsize(self.outputFitsPath) 124 125 # file information 126 child = Element('file') 127 root.append(child) 128 child.attrib['name'] = self.outputFitsFile 129 child.attrib['bytes'] = str(fileSize) 130 child.attrib['md5'] = md5sum 131 132 # now create doc and write to file 133 file = open(tmpPath, 'w') 134 ElementTree(root).write(file) 135 file.close() 136 137 # clunky way to prettify XML 138 os.popen("xmllint --format " + tmpPath + " > " + outPath) 139 # os.remove(tmpPath) 140 141 142 ''' 143 Gets PSPS-friendly survey type 144 ''' 145 def getPspsSurveyType(self): 146 147 if self.survey == "ThreePi": return "3PI" 148 elif self.survey == "MD04": return "MD04" 149 else: self.log("ERROR: Don't know this survey: " + self.survey) 150 151 ''' 152 Gets PSPS friendly batch type 153 ''' 154 def getPspsBatchType(self): 155 156 if self.batchType == "init": return "IN" 157 elif self.batchType == "detection": return "P2" 158 elif self.batchType == "stack": return "ST" 159 else: self.log("ERROR: Don't know this batch type: " + self.survey) 160 87 161 88 162 ''' … … 92 166 93 167 print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " | " + msg 168 169 ''' 170 Sets min and max obj ID using the provided table 171 ''' 172 def setMinMaxObjID(self, table): 173 174 sql = "SELECT MIN(objID), MAX(objID) FROM " + table 175 print 176 rs = self.localStmt.executeQuery(sql) 177 rs.first() 178 self.minObjID = rs.getLong(1) 179 self.maxObjID = rs.getLong(2) 180 181 print "MIN mAX = %d %d" % (self.minObjID, self.maxObjID) 94 182 95 183 ''' … … 317 405 self.log("Not implemented yet") 318 406 407 ''' 408 Updates provided table with DVO IDs from DVO table 409 ''' 410 def updateDvoIDs(self, table): 411 412 self.log("Updating table '" + table + "' with DVO IDs...") 413 sql = "UPDATE " + table + " AS a, dvo AS b SET \ 414 a.ippObjID = b.ippObjID, \ 415 a.objID = b.objID \ 416 WHERE a.ippDetectID = b.ippDetectID" 417 self.localStmt.execute(sql) 418 self.log("...done") 419 420 421 ''' 422 Creates a table for for ID matching 423 ''' 424 def createDvoTable(self): 425 426 self.log("Creating DVO table for ID matching") 427 sql = "DROP TABLE dvo" 428 self.localStmt.execute(sql) 429 sql = "CREATE TABLE dvo (ippDetectID BIGINT PRIMARY KEY, ippObjID BIGINT, objID BIGINT)" 430 self.localStmt.execute(sql) 431
Note:
See TracChangeset
for help on using the changeset viewer.
