#!/usr/bin/python
import os, sys, shutil
thisdir = os.path.dirname(os.path.abspath(sys.argv[0]))
sys.path.insert(0, os.path.abspath(os.path.join(thisdir, '../tko')))
import db

usage = "usage: delete_job_results <job tag>"

if len(sys.argv) < 2:
    print usage
    sys.exit(2)
tag = sys.argv[1]
resultsdir = os.path.abspath(os.path.join(thisdir, '../results', tag))

db = db.db()
if not db.find_job(tag):
    raise "Job tag %s does not exist in database" % tag

db.delete_job(tag)
shutil.rmtree(resultsdir)