#!/usr/bin/env jython

#
# This is a way to easily delete pending skychunks
#

import time
import sys
import os
import math
import logging.config

from ipptopsps import IppToPsps
from gpc1db import Gpc1Db
from datastore import Datastore
from dvoobjects import DvoObjects
from batch import Batch
from scratchdb import ScratchDb
# basically, "ippjython removepending.py skychunk_name " will remove pending batches


'''
Queue class
'''
class Queue(IppToPsps):

    '''
    Constructor
    '''
    def __init__(self, argv):
        super(Queue, self).__init__(argv)

        # print "inited ipptopsps"

        # create various objects
        self.gpc1Db = Gpc1Db(self.logger, self.config)
        # print "connect to gpc1"

        self.datastore = Datastore(self.logger, self.skychunk, self.ippToPspsDb)

        print "made datastore"

        # connect to scratch database
        self.scratchDb = ScratchDb(self.logger, self.config)

        print "connect to scratchdb"

        try:
            self.dvoObjects = DvoObjects(self.logger, self.config, self.skychunk, self.ippToPspsDb, self.scratchDb)
        except:
            self.exitProgram("Unable to create instance of DvoObject")
            raise

        print "got objects"

        self.skychunk.printAll()

        if len(argv) > 2: self.parsePollTimeArg(sys.argv[2])

    '''
    Main processing loop.
    Tiled area is defined in 'skychunk' and looks for available stage_ids for each tile and writes them to ippToPsps database ready for processing
    by one or more loading clients that may be running on any host
    '''
    def run(self):

        self.ippToPspsDb.removeAllBoxes()
        print "remove boxes" 
            

    '''
    Overrides base-class version
    '''
    def printUsage(self):
        super(Queue, self).printUsage("[<repeat time in hours>]")


'''
Start of program.
'''
try:
    queue = Queue(sys.argv)
    queue.run()
    queue.exitProgram("completed")
except: pass

