IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 30, 2012, 2:49:37 PM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/ippToPsps/jython/batch.py

    r32852 r33638  
    2121
    2222'''
    23 Base class of all batch types.
     23Abstract base class of all batch types.
    2424'''
    2525class Batch(object):
     
    2727    '''
    2828    Constructor
    29 
    30     >>> batch = Batch(1,2,3,4,5,6,7)
    31     >>> print batch.pspsVoTableFilePath
    32     "../config/2/tables.vot"
    3329    '''
    3430    def __init__(self,
    3531                 logger,
    36                  configPath,
    37                  doc,
     32                 config,
    3833                 gpc1Db,
    3934                 ippToPspsDb,
     35                 scratchDb,
    4036                 id,
    4137                 batchID,
    4238                 batchType,
    43                  fits):
     39                 fits,
     40                 useFullTables):
    4441
    4542        self.everythingOK = False
    4643        self.readHeader = False
    47         self.configPath = configPath
    48         self.doc = doc
     44        self.config = config
    4945        self.fits = fits
     46        self.useFullTables = useFullTables
    5047
    5148        # set up logging
     
    5956        self.gpc1Db = gpc1Db
    6057        self.ippToPspsDb = ippToPspsDb
     58        self.scratchDb = scratchDb
    6159        self.batchType = batchType;
    6260        self.pspsVoTableFilePath = "../config/" + batchType + "/tables.vot"
     
    7775               return
    7876
    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)
    8878
    8979        # TODO
    9080        self.tablesToExport = []
    9181
    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)
    9484        else:
    9585            self.surveyID = -1;
    9686       
    97         # get some options from the config
    98         self.testMode = int(self.doc.find("options/testMode").text)
    99         self.dataRelease = int(self.doc.find("metadata/dataRelease").text)
    100 
    10187        # create datastore object
    102         self.datastore = Datastore(self.logger, self.doc, self.ippToPspsDb)
     88        self.datastore = Datastore(self.logger, self.config, self.ippToPspsDb)
    10389
    10490        # get local storage location from config
    10591        self.batchName = Batch.getNameFromID(self.batchID)
    106         self.basePath = self.doc.find("localOutPath").text
    10792        self.subDir = Batch.getSubDir(
    108                 self.basePath,
     93                self.config.basePath,
    10994                self.batchType,
    110                 self.dvoGpc1Label)
     95                self.config.dvoLabel)
    11196
    11297        self.localOutPath = Batch.getOutputPath(
    113                 self.basePath,
     98                self.config.basePath,
    11499                self.batchType,
    115                 self.dvoGpc1Label,
     100                self.config.dvoLabel,
    116101                self.batchID)
    117102
     
    128113        self.logger.infoTitle("New " + self.batchType + " batch")
    129114        self.logger.infoPair("Batch name", self.batchName)
    130         self.logger.infoPair("Survey", self.survey)
    131115        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)
    134116        self.logger.infoBool("Use full DVO tables?", self.useFullTables)
    135117
     
    230212         if value != "NULL": return value
    231213         else:
    232              if not self.testMode: return "NULL"
     214             if not self.config.test: return "NULL"
    233215             header[key] = default
    234216             self.logger.infoPair("Hardcoding " + key + " to", header[key])
     
    259241        root.attrib['type'] = self.batchType
    260242        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
    262246        try: self.minObjID
    263247        except: pass
     
    278262
    279263        # 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
    283275
    284276
     
    290282        # set up filenams and paths
    291283        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)
    293285        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)
    295287
    296288        # tar directory
     
    395387
    396388      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
    398395
    399396      count = 0
     
    496493    def getIDsFromDVO(self):
    497494
    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)
    500497            return False
    501498
    502499        # TODO path to DVO prog hardcoded temporarily
    503         cmd = "../src/dvograbber " + self.configPath + " " + self.dvoLocation
     500        cmd = "../src/dvograbber " + self.config.settingsPath + " " + self.scratchDb.dbName + " " + self.config.dvoLocation
    504501        self.logger.infoPair("Running DVO", cmd)
    505502        p = Popen(cmd, shell=True, stdout=PIPE)
     
    539536                self.logger.errorPair("Aborting this batch", "unable to export tables to FITS file")
    540537            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)
    550550
    551551from datastore import Datastore
Note: See TracChangeset for help on using the changeset viewer.