blob: 156d61cbdc545ded93214408e3330c6125f02284 [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
mblighdcd57a82007-07-11 23:06:47 +000020import sys
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):
mbligh95fca572007-09-27 17:11:00 +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
mblighc99add62007-09-27 17:02:58 +000038def usage():
39 usage = "usage: %prog <control file>"
mbligh95fca572007-09-27 17:11:00 +000040 print usage
mblighdcd57a82007-07-11 23:06:47 +000041
42if __name__ == "__main__":
mbligh95fca572007-09-27 17:11:00 +000043 args = []
44 tmp_args = sys.argv[1:]
45 machines = None
46 while tmp_args:
47 if tmp_args[0] in ('-m', '--machines'):
48 if len(tmp_args) < 2:
49 raise('"' + tmp_args[0] + '" used, but then no machine defined')
50 machines = tmp_args[1]
51 tmp_args = tmp_args[2:]
52 else:
53 args.append(tmp_args[0])
54 tmp_args = tmp_args[1:]
mblighc99add62007-09-27 17:02:58 +000055
56 if len(args) < 1:
mbligh95fca572007-09-27 17:11:00 +000057 usage()
58 sys.exit(1)
mblighc99add62007-09-27 17:02:58 +000059
mbligh29aa9702007-08-09 22:41:43 +000060 control_file = args[0]
mbligh95fca572007-09-27 17:11:00 +000061 args = args[1:]
mblighc99add62007-09-27 17:02:58 +000062
63 if machines:
mbligh95fca572007-09-27 17:11:00 +000064 run(control_file, machines.split(','), args)
mbligh29aa9702007-08-09 22:41:43 +000065 else:
mbligh95fca572007-09-27 17:11:00 +000066 run(control_file, None, args)