#!/usr/bin/env jython

from datastore import Datastore
import logging
import sys
import getopt

from xml.etree.ElementTree import ElementTree, Element, tostring

from pslogger import PSLogger
from ipptopspsdb import IppToPspsDb



if len(sys.argv) < 3:
    print "** Usage: " + sys.argv[0] + " <configPath> <firstBatchToRemove> [<lastBatchToRemove>]"
    sys.exit(1)

CONFIG = sys.argv[1]
configDoc = ElementTree(file=CONFIG)

logging.setLoggerClass(PSLogger)
logger = logging.getLogger("removeFromDatastore")
logger.setup(configDoc, "removeFromDatastore")

ippToPspsDb = IppToPspsDb(logger, configDoc)
datastore = Datastore(logger, configDoc, ippToPspsDb)

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

