- Timestamp:
- Mar 30, 2012, 2:49:37 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/ippToPsps/jython/batch.py
r32852 r33638 21 21 22 22 ''' 23 Base class of all batch types.23 Abstract base class of all batch types. 24 24 ''' 25 25 class Batch(object): … … 27 27 ''' 28 28 Constructor 29 30 >>> batch = Batch(1,2,3,4,5,6,7)31 >>> print batch.pspsVoTableFilePath32 "../config/2/tables.vot"33 29 ''' 34 30 def __init__(self, 35 31 logger, 36 configPath, 37 doc, 32 config, 38 33 gpc1Db, 39 34 ippToPspsDb, 35 scratchDb, 40 36 id, 41 37 batchID, 42 38 batchType, 43 fits): 39 fits, 40 useFullTables): 44 41 45 42 self.everythingOK = False 46 43 self.readHeader = False 47 self.configPath = configPath 48 self.doc = doc 44 self.config = config 49 45 self.fits = fits 46 self.useFullTables = useFullTables 50 47 51 48 # set up logging … … 59 56 self.gpc1Db = gpc1Db 60 57 self.ippToPspsDb = ippToPspsDb 58 self.scratchDb = scratchDb 61 59 self.batchType = batchType; 62 60 self.pspsVoTableFilePath = "../config/" + batchType + "/tables.vot" … … 77 75 return 78 76 79 # get info from config 80 self.survey = self.doc.find("options/survey").text 81 self.pspsSurvey = self.doc.find("options/pspsSurvey").text 82 self.dvoGpc1Label = self.doc.find("dvo/gpc1Label").text 83 self.dvoLocation = self.doc.find("dvo/location").text 84 self.useFullTables = int(self.doc.find("dvo/useFullTables").text) 85 self.scratchDb = ScratchDb(logger, self.doc, self.useFullTables) 86 87 if not self.scratchDb.everythingOK: return 77 self.scratchDb.setUseFullTables(self.useFullTables) 88 78 89 79 # TODO 90 80 self.tablesToExport = [] 91 81 92 if self. survey != "":93 self.surveyID = self.scratchDb.getSurveyID(self. survey)82 if self.config.survey != "": 83 self.surveyID = self.scratchDb.getSurveyID(self.config.survey) 94 84 else: 95 85 self.surveyID = -1; 96 86 97 # get some options from the config98 self.testMode = int(self.doc.find("options/testMode").text)99 self.dataRelease = int(self.doc.find("metadata/dataRelease").text)100 101 87 # create datastore object 102 self.datastore = Datastore(self.logger, self. doc, self.ippToPspsDb)88 self.datastore = Datastore(self.logger, self.config, self.ippToPspsDb) 103 89 104 90 # get local storage location from config 105 91 self.batchName = Batch.getNameFromID(self.batchID) 106 self.basePath = self.doc.find("localOutPath").text107 92 self.subDir = Batch.getSubDir( 108 self. basePath,93 self.config.basePath, 109 94 self.batchType, 110 self. dvoGpc1Label)95 self.config.dvoLabel) 111 96 112 97 self.localOutPath = Batch.getOutputPath( 113 self. basePath,98 self.config.basePath, 114 99 self.batchType, 115 self. dvoGpc1Label,100 self.config.dvoLabel, 116 101 self.batchID) 117 102 … … 128 113 self.logger.infoTitle("New " + self.batchType + " batch") 129 114 self.logger.infoPair("Batch name", self.batchName) 130 self.logger.infoPair("Survey", self.survey)131 115 self.logger.infoPair("Survey ID", "%d" % self.surveyID) 132 self.logger.infoPair("Publishing to PSPS as survey", self.pspsSurvey)133 self.logger.infoPair("DVO location", self.dvoLocation)134 116 self.logger.infoBool("Use full DVO tables?", self.useFullTables) 135 117 … … 230 212 if value != "NULL": return value 231 213 else: 232 if not self. testMode: return "NULL"214 if not self.config.test: return "NULL" 233 215 header[key] = default 234 216 self.logger.infoPair("Hardcoding " + key + " to", header[key]) … … 259 241 root.attrib['type'] = self.batchType 260 242 root.attrib['timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 261 if self.batchType != "IN": root.attrib['survey'] = self.pspsSurvey 243 root.attrib['survey'] = self.config.pspsSurvey 244 245 # min/max object IDs 262 246 try: self.minObjID 263 247 except: pass … … 278 262 279 263 # clunky way to prettify XML 280 p = Popen("xmllint --format " + tmpPath + " > " + outPath, shell=True, stdout=PIPE) 281 p.wait() 282 os.remove(tmpPath) 264 try: 265 cmd = "xmllint --format " + tmpPath + " > " + outPath 266 p = Popen(cmd, shell=True, stdout=PIPE) 267 p.wait() 268 except: 269 self.logger.errorPair("Popen failed", cmd) 270 return False 271 finally: 272 os.remove(tmpPath) 273 274 return True 283 275 284 276 … … 290 282 # set up filenams and paths 291 283 tarFile = Batch.getTarFile(self.batchID) 292 tarPath = Batch.getTarPath(self. basePath, self.batchType, self.dvoGpc1Label, self.batchID)284 tarPath = Batch.getTarPath(self.config.basePath, self.batchType, self.config.dvoLabel, self.batchID) 293 285 tarballFile = Batch.getTarballFile(self.batchID) 294 tarballPath = Batch.getTarballPath(self. basePath, self.batchType, self.dvoGpc1Label, self.batchID)286 tarballPath = Batch.getTarballPath(self.config.basePath, self.batchType, self.config.dvoLabel, self.batchID) 295 287 296 288 # tar directory … … 395 387 396 388 self.logger.infoPair("Importing tables with filter", filter) 397 tables = stilts.treads(self.fits.getPath()) 389 390 try: 391 tables = stilts.treads(self.fits.getPath()) 392 except: 393 self.logger.errorPair("STILTS could not import from", self.fits.getPath()) 394 return False 398 395 399 396 count = 0 … … 496 493 def getIDsFromDVO(self): 497 494 498 if self.scratchDb.getRowCount( "dvoMeta") < 1:499 self.logger.error ("No DVO IDs found in dvoMeta")495 if self.scratchDb.getRowCount(self.scratchDb.dvoImagesTable) < 1: 496 self.logger.errorInfo("No DVO images found in", self.scratchDb.dvoImagesTable) 500 497 return False 501 498 502 499 # TODO path to DVO prog hardcoded temporarily 503 cmd = "../src/dvograbber " + self.config Path + " " + self.dvoLocation500 cmd = "../src/dvograbber " + self.config.settingsPath + " " + self.scratchDb.dbName + " " + self.config.dvoLocation 504 501 self.logger.infoPair("Running DVO", cmd) 505 502 p = Popen(cmd, shell=True, stdout=PIPE) … … 539 536 self.logger.errorPair("Aborting this batch", "unable to export tables to FITS file") 540 537 else: 541 self.writeBatchManifest() 542 if int(self.doc.find("options/publishToDatastore").text): 543 # tar and zip ready for publication to datastore 544 if self.tarAndZip(): 545 # now publish to the datastore 546 tarballFile = Batch.getTarballFile(self.batchID) 547 Batch.publishToDatastore(self.datastore, self.batchID, self.batchName, self.subDir, tarballFile) 548 549 if int(self.doc.find("options/reportNulls").text): self.reportNullsInAllPspsTables(False) 538 if self.writeBatchManifest(): 539 if self.config.datastorePublishing: 540 # tar and zip ready for publication to datastore 541 if self.tarAndZip(): 542 # now publish to the datastore 543 tarballFile = Batch.getTarballFile(self.batchID) 544 Batch.publishToDatastore( 545 self.datastore, 546 self.batchID, 547 self.batchName, 548 self.subDir, 549 tarballFile) 550 550 551 551 from datastore import Datastore
Note:
See TracChangeset
for help on using the changeset viewer.
