autoserv.py revision c99add655b54c688fc0b1eda98f74a6c208d01e7
1#!/usr/bin/python
2#
3# Copyright 2007 Google Inc. Released under the GPL v2
4
5"""
6Run an autoserv control file
7
8TODO(poirier): add a singleton logger
9TODO(poirier): maybe change the name "get_file" to "receive_file" ?
10TODO(poirier): change get(), send_file(), get_file() to consistantly recognize
11       paths that start with '~' as refering to the home directory
12"""
13
14__author__ = """
15mbligh@google.com (Martin J. Bligh),
16poirier@google.com (Benjamin Poirier),
17stutsman@google.com (Ryan Stutsman)
18"""
19
20import sys
21
22preamble = """\
23import os, sys
24
25import errors, hosts, autotest, kvm
26import source_kernel, rpm_kernel, deb_kernel
27from subcommand import *
28
29from utils import run, get_tmp_dir, sh_escape
30"""
31
32def run(control_file, machines, args):
33        namespace = dict({'machines': machines, 'args': args})
34
35	exec(preamble, namespace, namespace)
36	execfile(control_file, namespace, namespace)
37
38def usage():
39	usage = "usage: %prog <control file>"
40        print usage
41
42if __name__ == "__main__":
43        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:]
55
56	if len(args) < 1:
57                usage()
58                sys.exit(1)
59
60	control_file = args[0]
61        args = args[1:]
62
63	if machines:
64                run(control_file, machines.split(','), args)
65	else:
66                run(control_file, None, args)
67