IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 31, 2013, 4:13:09 PM (14 years ago)
Author:
eugene
Message:

split out config (static info) and skychunk (area being processed)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20121219/ippToPsps/jython/config.py

    r35075 r35076  
    11#!/usr/bin/env jython
    22
     3import sys
     4import os
    35import logging
    46from xml.etree.ElementTree import ElementTree, Element, tostring
     
    68from pslogger import PSLogger
    79
    8 
    910'''
    10 A class encapsulating a ippToPsps configuration. This information is stored in the 'config' table
    11 of the ipptopsps database, but there are some higher level config details in the 'settings.xml' file
     11A class encapsulating the globald ippToPsps configuration information.
     12This is stored in the 'settings.xml' file in the config directory
    1213'''
    1314class Config(object):
     
    1819    Basically reads the entire config and stores values to class variables
    1920    '''
    20     def __init__(self, programName, name, configDir):
     21    def __init__(self):
    2122
    22         self.programName = programName
    23         self.name = name
    24         self.configDir = configDir
     23        self.test = False
     24        for arg in sys.argv:
     25            if arg == "-test":
     26                self.test = True
     27                sys.argv.remove(arg)
     28            if arg == "-t":
     29                self.test = True
     30                sys.argv.remove(arg)
     31
     32        ## name of the top-level jython script
     33        self.programName = os.path.basename(sys.argv[0])
     34
     35        ## this is somewhat crude: ipptopsps programs are called like this:
     36        ## ippjython foo.py [chunk] [other options]
     37        ## the logging code (called below by getLogger) wants to include 'name' in the
     38        ## output file.  we blindly set name == argv[1]
     39        ## programs which are called without argv[1] will use 'none' in the log file
     40        if len(sys.argv) >= 2:
     41            self.name = sys.argv[1]
     42
     43        # XXX this probably goes in 'config.py'
     44        self.configDir = os.getenv("IPPTOPSPS_DATA")
     45        if self.configDir is None:
     46            self.configDir = "../config/"
     47        else:
     48            self.configDir = self.configDir + "/"
    2549
    2650        # self.configdir is set in ipptopsps.jy on init based on env(IPPTOPSPS_DATA)
    2751        # for test purposes, an uninstalled system may use the config information from
    2852        # a relative path
    29         if self.configDir is None:
    30           self.settingsPath = "../config/settings.xml" # TODO
    31         else:
    32           self.settingsPath = self.configDir + "settings.xml"
     53        self.settingsPath = self.configDir + "settings.xml"
    3354
    3455        self.logger = None
     
    3758        self.logPath = self.settingsDoc.find("logPath").text
    3859
    39         # XXX this is poor -- the czartool stuff is not related to
    40         # ipptopsps and should be moved elsewhere
    41         self.czarPlotsPath = self.settingsDoc.find("czarPlotsPath").text
    42 
    43         # this is the border (in degrees) that we place around any loading box of
    44         # PS1 pointings to ensure we pull a large enough area out of DVO
    45         # XXX this is a poor place to put this information -- it is completely gpc-specific. 
    46         # probably should go elsewhere
    47         self.BORDER = 1.65
    48         self.isLoaded = False
    49 
    50     '''
    51     Prints everything for this config
    52     '''
    53     def printAll(self):
    54 
    55         self.logger.infoTitle("Config")
    56 
    57         try:
    58             self.logger.infoSeparator()
    59             self.logger.infoPair("Config name", self.name)
    60             self.logger.infoPair("Survey", self.survey)
    61             self.logger.infoPair("Publishing to PSPS as survey", self.pspsSurvey)
    62             self.logger.infoPair("Loading epoch", self.epoch)
    63             self.logger.infoPair("Data release", "%d" % self.dataRelease)
    64             for batchType in self.batchTypes: self.logger.infoPair("Queuing batch type", batchType)
    65         except:
    66             pass
    67 
    68         self.printDvoInfo()
    69         self.printDatastoreInfo()
    70         self.printBoxCoords()
    71         self.printDeletionPolicy()
    72         try: self.logger.infoSeparator()
    73         except: pass
    74 
    75     '''
    76     Queuing this batch type?
    77     '''
    78     def queuingThisBatchType(self, batchType):
    79        if batchType in self.batchTypes: return 1
    80        return 0
     60        print "config.programName: ", self.programName
     61        print "config.configDir: ", self.configDir
     62        print "config.settingsPath: ", self.settingsPath
     63        print "config.logPath: ", self.logPath
     64        print "config.test: ", self.test
    8165
    8266    '''
     
    8569    def getLogger(self, host, pid, stdout=1, sendToFile=0):
    8670       
     71        print "get Logger: ", host, pid
    8772        logging.setLoggerClass(PSLogger)
     73        print "done Logger 1"
    8874        self.logger = logging.getLogger(self.programName)
    89         self.logger.setup(self.programName, self.logPath, self.name, host, pid, stdout, sendToFile)
     75        print "done Logger 2"
     76        if (self.name is None):
     77            self.logger.setup(self.programName, self.logPath, "none", host, pid, stdout, sendToFile)
     78        else:
     79            self.logger.setup(self.programName, self.logPath, self.name, host, pid, stdout, sendToFile)
     80        print "done Logger 3"
    9081
    9182        return self.logger
    92 
    93     '''
    94     Prints the currently set DVO info
    95     '''
    96     def printDvoInfo(self):
    97 
    98         try:
    99             self.logger.infoPair("DVO label", self.dvoLabel)
    100             self.logger.infoPair("DVO location", self.dvoLocation)
    101         except:
    102             pass
    103    
    104     '''
    105     Prints datastore info
    106     '''
    107     def printDatastoreInfo(self):
    108 
    109         try:
    110             self.logger.infoBool("Datastore publishing?", self.datastorePublishing)
    111             if self.datastorePublishing:
    112                 self.logger.infoPair("Datastore type", self.datastoreProduct)
    113                 self.logger.infoPair("Datastore product", self.datastoreType)
    114         except:
    115             pass
    116    
    117     '''
    118     Prints the current deletion policy
    119     '''
    120     def printDeletionPolicy(self):
    121 
    122         try:
    123             self.logger.infoBool("Deleting local?", self.deleteLocal)
    124             self.logger.infoBool("Deleting datastore?", self.deleteDatastore)
    125             self.logger.infoBool("Deleting DXLayer?", self.deleteDxLayer)
    126         except:
    127             pass
    128    
    129     '''
    130     Prints the currently set RA/Dec bounding box
    131     '''
    132     def printBoxCoords(self):
    133 
    134         try:
    135             self.logger.infoPair("RA limits", "%.1f -> %.1f" % (self.minRa, self.maxRa))
    136             self.logger.infoPair("Dec limits", "%.1f -> %.1f" % (self.minDec, self.maxDec))
    137             self.logger.infoPair("Loading box size", "%.1f degrees" % self.boxSize)
    138         except:
    139             pass
    140    
    14183
    14284    '''
     
    14789    def getDbUser(self, dbType): return self.settingsDoc.find(dbType +"/user").text
    14890    def getDbPassword(self, dbType): return self.settingsDoc.find(dbType +"/password").text
    149 
Note: See TracChangeset for help on using the changeset viewer.