import getopt

test = None
logdir = None


def usage():
    print "usage: -t <test name> -m <machines> -l <log dir>"

def run(client):
    m = hosts.create_host(client)
    at = autotest.Autotest()

    results_dir = os.path.join(logdir, client)
    at.run_test(test, results_dir, m)


def main():
    global test, logdir, args

    try:
        opts, args = getopt.getopt(args, 't:l:', [])
    except getopt.GetoptError, e:
        usage()
        print e
        sys.exit(1)

    for flag, value in opts:
        if flag == '-t':
            test = value
        elif flag == '-l':
            logdir = value

    if test is None or logdir is None:
        usage()
        sys.exit(1)

    print "Going to launch %s on %r with log dir of %s." % (test, machines, logdir)
    parallel_simple(run, machines)


main()