#!/usr/bin/python -u
#
# autotest <control file> - run the autotest control file specified.
#
import os, sys, shutil
import common
from optparse import OptionParser
from autotest_lib.client.bin import job


# 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")

parser.add_option("-l", "--external_logging", dest="log", action="store_true",
                        default=False, help="enable external logging")

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,
           options.log)
