blob: 2634699909d31e628297ac0350e4e3df1486220d [file] [log] [blame]
mbligh6203ace2007-10-04 21:54:24 +00001#!/usr/bin/python -u
mblighdcd57a82007-07-11 23:06:47 +00002#
3# Copyright 2007 Google Inc. Released under the GPL v2
4
mblighc8949b82007-07-23 16:33:58 +00005"""
6Run an autoserv control file
mblighdcd57a82007-07-11 23:06:47 +00007
8TODO(poirier): add a singleton logger
9TODO(poirier): maybe change the name "get_file" to "receive_file" ?
mblighc8949b82007-07-23 16:33:58 +000010TODO(poirier): change get(), send_file(), get_file() to consistantly recognize
mbligh95fca572007-09-27 17:11:00 +000011 paths that start with '~' as refering to the home directory
mblighdcd57a82007-07-11 23:06:47 +000012"""
13
mblighc8949b82007-07-23 16:33:58 +000014__author__ = """
15mbligh@google.com (Martin J. Bligh),
16poirier@google.com (Benjamin Poirier),
17stutsman@google.com (Ryan Stutsman)
18"""
mblighdcd57a82007-07-11 23:06:47 +000019
mbligh5fadbfe2007-10-06 21:12:06 +000020import sys, os
mblighdcd57a82007-07-11 23:06:47 +000021
mbligh29aa9702007-08-09 22:41:43 +000022preamble = """\
23import os, sys
24
25import errors, hosts, autotest, kvm
26import source_kernel, rpm_kernel, deb_kernel
27from subcommand import *
28
mbligh03dd0792007-08-28 10:26:46 +000029from utils import run, get_tmp_dir, sh_escape
mbligh29aa9702007-08-09 22:41:43 +000030"""
31
mblighc99add62007-09-27 17:02:58 +000032def run(control_file, machines, args):
mbligh5fadbfe2007-10-06 21:12:06 +000033 namespace = dict({ 'machines' : machines, 'args' : args })
mblighdcd57a82007-07-11 23:06:47 +000034
mbligh29aa9702007-08-09 22:41:43 +000035 exec(preamble, namespace, namespace)
36 execfile(control_file, namespace, namespace)
mblighdcd57a82007-07-11 23:06:47 +000037
mbligh5fadbfe2007-10-06 21:12:06 +000038
mblighc99add62007-09-27 17:02:58 +000039def usage():
40 usage = "usage: %prog <control file>"
mbligh95fca572007-09-27 17:11:00 +000041 print usage
mblighdcd57a82007-07-11 23:06:47 +000042
mbligh5fadbfe2007-10-06 21:12:06 +000043
mblighdcd57a82007-07-11 23:06:47 +000044if __name__ == "__main__":
mbligh95fca572007-09-27 17:11:00 +000045 args = []
46 tmp_args = sys.argv[1:]
47 machines = None
48 while tmp_args:
49 if tmp_args[0] in ('-m', '--machines'):
50 if len(tmp_args) < 2:
51 raise('"' + tmp_args[0] + '" used, but then no machine defined')
52 machines = tmp_args[1]
53 tmp_args = tmp_args[2:]
54 else:
55 args.append(tmp_args[0])
56 tmp_args = tmp_args[1:]
mblighc99add62007-09-27 17:02:58 +000057
58 if len(args) < 1:
mbligh95fca572007-09-27 17:11:00 +000059 usage()
60 sys.exit(1)
mblighc99add62007-09-27 17:02:58 +000061
mbligh29aa9702007-08-09 22:41:43 +000062 control_file = args[0]
mbligh95fca572007-09-27 17:11:00 +000063 args = args[1:]
mblighc99add62007-09-27 17:02:58 +000064
65 if machines:
mbligh95fca572007-09-27 17:11:00 +000066 run(control_file, machines.split(','), args)
mbligh29aa9702007-08-09 22:41:43 +000067 else:
mbligh95fca572007-09-27 17:11:00 +000068 run(control_file, None, args)