IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31809


Ignore:
Timestamp:
Jul 1, 2011, 8:54:16 AM (15 years ago)
Author:
rhenders
Message:

implementing new dataRelease, useFullTables, force, testmode, publishToDatastore and reportNull options from config; now tarball creation done in same method as publish to datastore since; config XML document object passed into constructor; implemented printMe() method, which is overriden in all subclasses; improvements to logging messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/batch.py

    r31720 r31809  
    3434    def __init__(self,
    3535                 logger,
     36                 doc,
    3637                 gpc1Db,
    3738                 ippToPspsDb,
    38                  scratchDb,
    3939                 id,
    4040                 batchType,
    4141                 inputFitsPath="",
    42                  survey="",
    43                  useFullTables=False):
     42                 survey=""):
    4443
    4544        self.everythingOK = False
    4645        self.readHeader = False
     46        self.doc = doc
    4747
    4848        # set up logging
     
    5555        self.gpc1Db = gpc1Db
    5656        self.ippToPspsDb = ippToPspsDb
    57         self.scratchDb = scratchDb
    5857        self.batchType = batchType;
    5958        self.pspsVoTableFilePath = "../config/" + batchType + "/tables.vot"
    6059        self.inputFitsPath = inputFitsPath
    6160        self.survey = survey
    62         self.useFullTables = useFullTables
    6361
    6462        if self.alreadyProcessed(): return
     63
     64        # get dvo info from config
     65        dvoName = self.doc.find("dvo/name").text
     66        self.dvoLocation = self.doc.find("dvo/location").text
     67        self.useFullTables = int(self.doc.find("dvo/useFullTables").text)
     68        self.scratchDb = ScratchDb(logger, self.useFullTables)
    6569
    6670        # do we have an input file?
     
    7276        self.tablesToExport = []
    7377
    74         # open config
    75         self.doc = ElementTree(file="config.xml")
    76 
    7778        if self.survey != "":
    7879            self.surveyID = self.scratchDb.getSurveyID(self.survey)
    79    
    80             # get dvo info from config
    81             dvoName = self.doc.find("dvo_" + self.survey + "/name").text
    82             self.dvoLocation = self.doc.find("dvo_" + self.survey + "/location").text
    8380        else:
    84             dvoName = ""
    85             self.dvoLocation = ""
    8681            self.surveyID = -1;
     82
    8783       
    8884        # get some options from the config
    89         self.dataRelease = self.doc.find("metadata/dataRelease").text
     85        self.testMode = int(self.doc.find("options/testMode").text)
     86        self.dataRelease = int(self.doc.find("metadata/dataRelease").text)
    9087
    9188        # get datastore info from config
     
    9592        self.batchID = self.ippToPspsDb.createNewBatch(
    9693                self.getPspsBatchType(),
     94                self.id,
    9795                survey,
    9896                dvoName,
     
    120118
    121119        self.logger.debug("Batch destructor")
     120
     121    '''
     122    Prints metadata to the log
     123    '''
     124    def printMe(self):
     125
     126        self.logger.info("New batch: ")
     127        self.logger.info("Batch type:             " + self.batchType)
     128        self.logger.info("Survey:                 " + self.survey)
     129        self.logger.info("Survey ID:              %d" % self.surveyID)
     130        self.logger.info("Test mode?              %d" % self.testMode)
     131        self.logger.info("DVO location:           " + self.dvoLocation)
     132        self.logger.info("Use full DVO tables?:   %d" % self.useFullTables)
     133        self.logger.info("Input FITS file:        " + self.inputFitsPath)
    122134
    123135
     
    240252
    241253    '''
    242     tar and zips batch directory
    243     '''
    244     def createTarball(self):
     254    Publishes this batch to the datastore
     255    '''
     256    def publishToDatastore(self):
    245257     
    246         if self.doc.find("options/createTarball").text == "false": return
    247 
    248258        # set up filenams and paths
    249259        tarFile = self.batchName + ".tar"
    250260        tarPath = self.subDir + "/" + tarFile
    251261
    252         self.tarballFile = tarFile + ".gz"
    253         tarballPath = self.subDir + "/" + self.tarballFile
     262        tarballFile = tarFile + ".gz"
     263        tarballPath = self.subDir + "/" + tarballFile
    254264
    255265        # tar directory
     
    267277        shutil.rmtree(self.localOutPath)
    268278
    269     '''
    270     Publishes this batch to the datastore
    271     '''
    272     def publishToDatastore(self):
    273 
    274         if self.doc.find("options/publishToDatastore").text == "false": return
    275 
    276         if self.datastore.publish(self.batchName, self.subDir, self.tarballFile, "tgz"):
     279        # now publish to the datastore
     280        if self.datastore.publish(self.batchName, self.subDir, tarballFile, "tgz"):
    277281            self.ippToPspsDb.updateLoadedToDatastore(self.batchID, 1)
    278282
     
    282286    def getBatchFriendlySurveyType(self):
    283287
    284         return "SCR" # TODO
    285 
     288        #return "SCR" # TODO
    286289        try:
    287290            self.survey
     
    395398    def importIppTables(self, filter=""):
    396399
    397       self.logger.info("Attempting to import tables from input FITS file")
     400      self.logger.info("Attempting to import tables from input FITS file with regex " + filter)
    398401      tables = stilts.treads(self.inputFitsPath)
    399402
     
    433436        _tables = []
    434437
    435         self.logger.info("Selecting database tables")
     438        self.logger.info("Selecting database tables for export")
    436439        for table in self.tablesToExport:
    437440
     
    472475    def reportNullsInAllPspsTables(self, showPartials):
    473476
    474         if self.doc.find("options/reportNulls").text == "false": return
    475 
    476477        for table in self.pspsTables:
    477478            self.scratchDb.reportNulls(table.name, showPartials)
     
    527528
    528529        self.createEmptyPspsTables()
    529         #self.importIppTables()
     530        self.importIppTables()
    530531        if self.populatePspsTables():
    531532            if self.exportPspsTablesToFits():
    532533                self.writeBatchManifest()
    533                 self.createTarball()
    534                 self.publishToDatastore()
    535                 self.reportNullsInAllPspsTables(False)
    536                 #sys.exit()
     534                if int(self.doc.find("options/publishToDatastore").text): self.publishToDatastore()
     535                if int(self.doc.find("options/reportNulls").text): self.reportNullsInAllPspsTables(False)
     536
    537537        self.logger.info("Finished.")
    538 
    539 
     538        if self.testMode: sys.exit()
     539
     540
Note: See TracChangeset for help on using the changeset viewer.