IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 12, 2011, 8:35:57 AM (15 years ago)
Author:
rhenders
Message:

restructured to that it polls indefinitely looking for new P2 then ST items; batch-type command-line arg is now optional; added a lot of comments

File:
1 edited

Legend:

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

    r31845 r31863  
    1414from detectionbatch import DetectionBatch
    1515
    16 # check we have a batch type
    17 if len(sys.argv) < 2:
    18     print "\nERROR: please provie a batchType: P2 or ST\n"
    19     sys.exit(1)
     16'''
     17Queues up all available stuff for this batch type
     18'''
     19def queueItems(batchType):
    2020
    21 batchType  = sys.argv[1]
     21    logger.infoSeparator()
    2222
    23 logging.config.fileConfig("logging.conf")
    24 logging.setLoggerClass(PSLogger)
    25 logger = logging.getLogger("ippToPspsLog")
    26 logger.setLevel(logging.INFO)
     23    # gett list of all items available in DVO
     24    allIDs = gpc1Db.getIDsInThisDVODbForThisStage(DVOGPC1LABEL, batchType)
     25    logger.infoPair("All %s items in DVO" % batchType, "%d" % len(allIDs))
    2726
    28 configDoc = ElementTree(file="config.xml")
    29 dvoGpc1Label = configDoc.find("dvo/gpc1Label").text
     27    # if in FORCE mode, then queue full list
     28    if FORCE:
     29        ids = allIDs
    3030
    31 gpc1Db = Gpc1Db(logger, configDoc)
    32 ippToPspsDb = IppToPspsDb(logger, configDoc)
    33 POLLPERIOD = 600
    34 FORCE = int(configDoc.find("options/force").text)
    35 TEST = int(configDoc.find("options/testMode").text)
    36 EPOCH = configDoc.find("options/epoch").text
    37 PUBLISH = int(configDoc.find("options/publishToDatastore").text)
     31    # if not in TEST mode, then only queue un-processed items
     32    else:
     33        processedIDs = ippToPspsDb.getProcessedIDsForThisStage(batchType, EPOCH)
     34        logger.infoPair("Processed %s items" % batchType, "%d" % len(processedIDs))
     35        ids = list(set(allIDs) - set(processedIDs))
     36        logger.infoPair("Unprocessed %s items" % batchType, "%d" % len(ids))
    3837
    39 if FORCE and PUBLISH:
    40    response = raw_input("Are you sure you want to publish data with the 'force' option enabled (y/n)? ")
    41    if response != "y": sys.exit(1)
     38    logger.infoPair("%s items queued" % batchType, "%d" % len(ids))
    4239
    43 logger.infoSeparator()
    44 logger.infoPair("Batch type", batchType)
    45 logger.infoPair("Loading epoch", EPOCH)
    46 logger.infoPair("Forcing?", "%d" % FORCE)
    47 logger.infoPair("Test mode?", "%d" % TEST)
    48 logger.infoPair("DVO gpc1 label", dvoGpc1Label)
    49 
    50 while True:
    51 
    52     if FORCE:
    53         logger.infoPair("Querying GPC1 for", "all available IDs")
    54         ids = gpc1Db.getIDsInThisDVODbForThisStage(dvoGpc1Label, batchType)
    55 
    56     else:
    57         logger.infoPair("Querying GPC1 for", "all unprocessed IDs")
    58         ids = ippToPspsDb.getUnprocessedIDsForThisStage(dvoGpc1Label, batchType, EPOCH)
    59 
    60     logger.infoPair("Queuing", "%d items" % len(ids))
    61 
     40    # loop round IDs of all items to be processed
    6241    for id in ids:
    6342
     
    8059        batch.run()
    8160
     61        # if in TEST mode, then quit after one batch
    8262        if TEST: break
    8363
     64
     65'''
     66Start of program.
     67'''
     68
     69# check to see if we have a batch type
     70if len(sys.argv) > 1: BATCHTYPE  = sys.argv[1]
     71else: BATCHTYPE = "ALL"
     72
     73# set up logging
     74logging.config.fileConfig("logging.conf")
     75logging.setLoggerClass(PSLogger)
     76logger = logging.getLogger("ippToPspsLog")
     77logger.setLevel(logging.INFO)
     78
     79# open config file
     80configDoc = ElementTree(file="config.xml")
     81
     82# create database objects
     83gpc1Db = Gpc1Db(logger, configDoc)
     84ippToPspsDb = IppToPspsDb(logger, configDoc)
     85
     86# get values from the configutaion file
     87POLLPERIOD = 600
     88DVOGPC1LABEL = configDoc.find("dvo/gpc1Label").text
     89FORCE = int(configDoc.find("options/force").text)
     90TEST = int(configDoc.find("options/testMode").text)
     91EPOCH = configDoc.find("options/epoch").text
     92PUBLISH = int(configDoc.find("options/publishToDatastore").text)
     93
     94# prompt user: FORCE and PUBLISH is a dangerous combination
     95if FORCE and PUBLISH:
     96   response = raw_input("Are you sure you want to publish data with the 'force' option enabled (y/n)? ")
     97   if response != "y": sys.exit(1)
     98
     99# print info to log
     100logger.infoSeparator()
     101logger.infoPair("Batch type", BATCHTYPE)
     102logger.infoPair("Loading epoch", EPOCH)
     103logger.infoPair("Forcing?", "%d" % FORCE)
     104logger.infoPair("Test mode?", "%d" % TEST)
     105logger.infoPair("DVO gpc1 label", DVOGPC1LABEL)
     106
     107'''
     108Main processing loop:
     109
     110 1) queues available P2 batches
     111 2) queues available ST batches
     112 3) if in test mode, quits
     113 4) otherwise, waits then repeats from 1
     114
     115'''
     116while True:
     117
     118    # queue all items for all batch types, sequentially
     119    if BATCHTYPE == "ALL":
     120        queueItems("P2")
     121        queueItems("ST")
     122    # queue only items for the user-specified batch type
     123    else:
     124        queueItems(BATCHTYPE)
     125
     126    # in the TEST mode, we quit after submitting one batch
    84127    if TEST: break
    85128
    86     # wait for ten minutes before checking for new ids
     129    # wait for the POLLPERIOD before checking for new ids
    87130    logger.infoPair("Finished. Waiting for", "%.1f minutes before checking DVO for new items" % (POLLPERIOD/60.0))
    88131    time.sleep(POLLPERIOD)
    89132
    90133
    91 
Note: See TracChangeset for help on using the changeset viewer.