#!/usr/bin/env jython

from datastore import Datastore
import logging
import sys
import getopt

from ipptopsps import IppToPsps
from datastore import Datastore

'''
DatastoreRemover class
'''
class DatastoreRemover(IppToPsps):

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

        if len(sys.argv) < 3:
            self.printUsage()
            self.exitProgram("incorrect args")

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

    '''
    Runs...
    '''
    def run(self):

        if len(sys.argv) < 4:
           self.datastore.remove(str(sys.argv[2]))
        else:
           self.datastore.removeRange(str(sys.argv[2]), str(sys.argv[3]))

    '''
    Overrides base-class version
    '''
    def printUsage(self):
        super(DatastoreRemover, self).printUsage("<firstBatchToRemove> [<lastBatchToRemove>]")


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

