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/ipptopsps.py

    r35063 r35076  
    11#!/usr/bin/env jython
     2# EAM : config -> skychunk DONE
    23
    34import signal
     
    910
    1011from config import Config
     12from skychunk import Skychunk
    1113from pslogger import PSLogger
    1214from ipptopspsdb import IppToPspsDb
     
    2325    def __init__(self, argv, logToStdout=1, logToFile=0):
    2426
    25         testmode = False
    26         for arg in sys.argv:
    27             if arg == "-test":
    28                 testmode = True
    29                 sys.argv.remove(arg)
    30             if arg == "-t":
    31                 testmode = True
    32                 sys.argv.remove(arg)
    33 
    34         # are the arsg ok? all programs require a config name
     27        # set up config object (global config information, also parse command-line options, eg -test / -t)
     28        self.config = Config()
     29
     30        # are the args ok? all programs require a config name
    3531        if len(sys.argv) < 2:
    3632            self.printUsage()
     
    3834
    3935        # some class constants
    40         self.PROGNAME = os.path.basename(sys.argv[0])
    41         CONFIGNAME = sys.argv[1]
    4236        self.HOST = socket.gethostname()
    4337        self.PID = os.getpid()
     
    4741        self.SECONDS = None
    4842
    49         self.configDir = os.getenv("IPPTOPSPS_DATA")
    50         if self.configDir is not None:
    51             self.configDir = self.configDir + "/"
    52 
    53         self.createNewConfig = False
    54         self.rotateConfigs = False
    55         # a new config?
    56         if CONFIGNAME == "edit": self.createNewConfig = True
    57         # should we rotate configs for this program?
    58         elif CONFIGNAME == "all": self.rotateConfigs = True
    59 
    60         # set up config object
    61         self.config = Config(self.PROGNAME, CONFIGNAME, self.configDir)
    62         self.config.test = testmode
    63 
    64         if self.config.test: print "using test mode"
    65         else: print "not using test mode"
    66 
    6743        self.logger = self.config.getLogger(self.HOST, self.PID, logToStdout, logToFile)
    6844
     45        # argv[1] -> self.skychunk.name
     46        self.skychunk = Skychunk(self.logger)
     47        print "here... "
     48
    6949        # create connection to databases database
    7050        try:
    71             self.ippToPspsDb = IppToPspsDb(self.logger, self.config)
     51            self.ippToPspsDb = IppToPspsDb(self.logger, self.config, self.skychunk)
    7252        except:
    7353            self.exitProgram("Could not connect to ipptopsps Db")
    7454            raise
    7555
     56        print "here... "
     57
    7658        self.checkClientStatus()
     59        print "here... "
    7760
    7861        # catch Ctrl-C signal
    7962        signal.signal(signal.SIGINT, self.signal_handler)
     63        print "here... "
    8064
    8165        # title for log
    8266        self.logger.infoSeparator()
    83         self.logger.infoTitle("ippToPsps '" + self.PROGNAME + "' started")
     67        self.logger.infoTitle("ippToPsps '" + self.config.programName + "' started")
    8468        self.logger.infoPair("Host", self.HOST)
    8569        self.logger.infoPair("PID", "%d" % self.PID)
    86         self.logger.infoPair("Config", self.config.name)
     70        self.logger.infoPair("Skychunk", self.skychunk.name)
     71        print "here... "
    8772
    8873    '''
     
    122107
    123108        # write message to log or stdout if no logger set up
    124         msg = sys.argv[0] + " <configName|all|edit> " + extra
     109        msg = sys.argv[0] + " <skychunkName|all|edit> " + extra
    125110        try:
    126111            self.logger.errorPair("Usage:", msg)
     
    129114
    130115    '''
    131     Refreshes the config then recreates objects with new settings
    132     '''
    133     def refreshConfig(self):
    134 
    135         # new config?
    136         if self.createNewConfig:
    137             self.ippToPspsDb.editConfig()
    138             self.ippToPspsDb.setConfigForThisClient(self.config.name, self.HOST, self.PID)
    139             self.createNewConfig = False
    140 
    141         # if we are rotating configs, then look for next active one in list
    142         if self.rotateConfigs:
    143             self.ippToPspsDb.getConfigForThisClient(self.HOST, self.PID)
    144             configs = self.ippToPspsDb.getActiveConfigList()
     116    Refreshes the skychunk then recreates objects with new settings
     117    '''
     118    def refreshSkychunk(self):
     119
     120        print "refresh... "
     121        print "self.skychunk.createNewSkychunk:  ", self.skychunk.createNewSkychunk
     122
     123        # new skychunk?
     124        if self.skychunk.createNewSkychunk:
     125            print "self.skychunk.createNewSkychunk:  ", self.skychunk.createNewSkychunk
     126            self.ippToPspsDb.editSkychunk()
     127            print "self.skychunk.createNewSkychunk:  ", self.skychunk.createNewSkychunk
     128            self.ippToPspsDb.setSkychunkForThisClient(self.skychunk.name, self.HOST, self.PID)
     129            print "self.skychunk.createNewSkychunk:  ", self.skychunk.createNewSkychunk
     130            self.skychunk.createNewSkychunk = False
     131
     132        print "refresh... "
     133        # if we are rotating skychunks, then look for next active one in list
     134        if self.skychunk.rotateSkychunks:
     135            self.ippToPspsDb.getSkychunkForThisClient(self.HOST, self.PID)
     136            skychunks = self.ippToPspsDb.getActiveSkychunkList()
    145137             
    146138            i = 1
    147             for config in configs:
    148                if config == self.config.name: break
     139            for skychunk in skychunks:
     140               if skychunk == self.skychunk.name: break
    149141               i += 1
    150142
    151             if i >= len(configs): newConfig = configs[0]
    152             else: newConfig = configs[i]
    153 
    154             self.ippToPspsDb.setConfigForThisClient(newConfig, self.HOST, self.PID)
    155 
    156         return self.ippToPspsDb.readConfig(self.HOST, self.PID)
    157 
    158     '''
    159     All implementing subclasses (programs) should call this method once in a while to see if it should be paused or killed, otherwise this updates the clients table with current time and reloads the config data
     143            if i >= len(skychunks): newSkychunk = skychunks[0]
     144            else: newSkychunk = skychunks[i]
     145
     146            self.ippToPspsDb.setSkychunkForThisClient(newSkychunk, self.HOST, self.PID)
     147
     148        print "refresh... "
     149        return self.ippToPspsDb.readSkychunk(self.HOST, self.PID)
     150
     151    '''
     152    All implementing subclasses (programs) should call this method once in a while to see if it should be paused or killed, otherwise this updates the clients table with current time and reloads the skychunk data
    160153    '''
    161154    def checkClientStatus(self):
    162155
    163         self.ippToPspsDb.updateClient(self.PROGNAME, self.HOST, self.PID)
    164 
     156        print "stat... "
     157        self.ippToPspsDb.updateClient(self.config.programName, self.HOST, self.PID)
     158
     159        print "stat... "
    165160        if self.ippToPspsDb.isKilled(self.HOST, self.PID):
    166161            self.exitProgram("killed via Db")
    167162       
    168         # this loop pauses the process if we have no config or we have set it to pause
     163        # this loop pauses the process if we have no skychunk or we have set it to pause
    169164        firstTimeIn = True
    170         while not self.refreshConfig() or self.ippToPspsDb.isPaused(self.HOST, self.PID):
    171 
    172             self.ippToPspsDb.updateClient(self.PROGNAME, self.HOST, self.PID)
     165        print "stat... "
     166        while not self.refreshSkychunk() or self.ippToPspsDb.isPaused(self.HOST, self.PID):
     167
     168            print "stat... "
     169            self.ippToPspsDb.updateClient(self.config.programName, self.HOST, self.PID)
    173170            if self.ippToPspsDb.isKilled(self.HOST, self.PID):
    174171                self.exitProgram("killed while paused")
     
    177174            time.sleep(self.PAUSEPERIOD)
    178175
     176        print "stat done... "
     177
    179178
    180179    '''
     
    193192        # write message to log or stdout if no logger set up
    194193        try:
    195             self.logger.infoPair(self.PROGNAME + " exited", exitReason)
     194            self.logger.infoPair(self.config.programName + " exited", exitReason)
    196195        except:
    197196            print "*** Program exited: " + exitReason
     
    204203
    205204        sys.exit(0)
    206    
    207 
Note: See TracChangeset for help on using the changeset viewer.