Changeset 31863
- Timestamp:
- Jul 12, 2011, 8:35:57 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/ipptopsps.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/ipptopsps.py
r31845 r31863 14 14 from detectionbatch import DetectionBatch 15 15 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 ''' 17 Queues up all available stuff for this batch type 18 ''' 19 def queueItems(batchType): 20 20 21 batchType = sys.argv[1] 21 logger.infoSeparator() 22 22 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)) 27 26 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 30 30 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)) 38 37 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)) 42 39 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 62 41 for id in ids: 63 42 … … 80 59 batch.run() 81 60 61 # if in TEST mode, then quit after one batch 82 62 if TEST: break 83 63 64 65 ''' 66 Start of program. 67 ''' 68 69 # check to see if we have a batch type 70 if len(sys.argv) > 1: BATCHTYPE = sys.argv[1] 71 else: BATCHTYPE = "ALL" 72 73 # set up logging 74 logging.config.fileConfig("logging.conf") 75 logging.setLoggerClass(PSLogger) 76 logger = logging.getLogger("ippToPspsLog") 77 logger.setLevel(logging.INFO) 78 79 # open config file 80 configDoc = ElementTree(file="config.xml") 81 82 # create database objects 83 gpc1Db = Gpc1Db(logger, configDoc) 84 ippToPspsDb = IppToPspsDb(logger, configDoc) 85 86 # get values from the configutaion file 87 POLLPERIOD = 600 88 DVOGPC1LABEL = configDoc.find("dvo/gpc1Label").text 89 FORCE = int(configDoc.find("options/force").text) 90 TEST = int(configDoc.find("options/testMode").text) 91 EPOCH = configDoc.find("options/epoch").text 92 PUBLISH = int(configDoc.find("options/publishToDatastore").text) 93 94 # prompt user: FORCE and PUBLISH is a dangerous combination 95 if 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 100 logger.infoSeparator() 101 logger.infoPair("Batch type", BATCHTYPE) 102 logger.infoPair("Loading epoch", EPOCH) 103 logger.infoPair("Forcing?", "%d" % FORCE) 104 logger.infoPair("Test mode?", "%d" % TEST) 105 logger.infoPair("DVO gpc1 label", DVOGPC1LABEL) 106 107 ''' 108 Main 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 ''' 116 while 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 84 127 if TEST: break 85 128 86 # wait for t en minutesbefore checking for new ids129 # wait for the POLLPERIOD before checking for new ids 87 130 logger.infoPair("Finished. Waiting for", "%.1f minutes before checking DVO for new items" % (POLLPERIOD/60.0)) 88 131 time.sleep(POLLPERIOD) 89 132 90 133 91
Note:
See TracChangeset
for help on using the changeset viewer.
