#!/usr/bin/python -u
#
# autotest <control file> - run the autotest control file specified.
#
from check_version import check_python_version
check_python_version()

import os, sys, shutil
import job, kernel, test
from common.error import *
from autotest_utils import *
from optparse import OptionParser

# Use the name of the binary to find the real installation directory
# aka $AUTODIR.  Update our path to include the $AUTODIR/bin/tests
# directory and ensure we have $AUTODIR in our environment.
autodirbin = os.path.abspath(os.path.dirname(sys.argv[0]))
autodir = os.path.dirname(autodirbin)

##print 'AUTODIRBIN: ' + autodirbin
##print 'AUTODIR: ' + autodir

sys.path.insert(0, autodirbin)

os.environ['AUTODIR'] = autodir
os.environ['AUTODIRBIN'] = autodirbin
os.environ['PYTHONPATH'] = autodirbin

parser = OptionParser()

parser.add_option("-c", "--continue", dest="cont", action="store_true", 
			default=False, help="continue previously started job")
		  
parser.add_option("-t", "--tag", dest="tag", type="string", default="default",
			help="set the job tag")

parser.add_option("-H", "--harness", dest="harness", type="string", default='',
			help="set the harness type")

def usage():
	parser.print_help()
	sys.exit(1)

options, args = parser.parse_args()

# Check for a control file.
if len(args) != 1:
	usage()

# JOB: run the specified job control file.
job.runjob(os.path.abspath(args[0]), options.cont, options.tag, options.harness)
