blob: 5df40aa1a2f0e4a6ef56258edbae4d893ed6eb02 [file] [log] [blame]
mblighdcd57a82007-07-11 23:06:47 +00001#!/usr/bin/python
2#
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
11 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
21import optparse
22
23
mblighdcd57a82007-07-11 23:06:47 +000024def parse_args():
mbligh29aa9702007-08-09 22:41:43 +000025 usage = "usage: %prog <control file>"
26 parser = optparse.OptionParser(usage)
27 parser.add_option('-m', '--machines', dest='machines', type='string')
28 (options, arg) = parser.parse_args()
mblighdcd57a82007-07-11 23:06:47 +000029 return (options, arg)
30
31
mbligh29aa9702007-08-09 22:41:43 +000032preamble = """\
33import os, sys
34
35import errors, hosts, autotest, kvm
36import source_kernel, rpm_kernel, deb_kernel
37from subcommand import *
38
mbligh03dd0792007-08-28 10:26:46 +000039from utils import run, get_tmp_dir, sh_escape
mbligh29aa9702007-08-09 22:41:43 +000040"""
41
42def run(control_file, machines):
43 namespace = dict({'machines': machines})
mblighdcd57a82007-07-11 23:06:47 +000044
mbligh29aa9702007-08-09 22:41:43 +000045 exec(preamble, namespace, namespace)
46 execfile(control_file, namespace, namespace)
mblighdcd57a82007-07-11 23:06:47 +000047
48
49if __name__ == "__main__":
50 (options, args) = parse_args()
51 if len(args) != 1:
52 parser.error("program takes one argument")
53 sys.exit(1)
mbligh29aa9702007-08-09 22:41:43 +000054 control_file = args[0]
55 if options.machines:
56 run(control_file, options.machines.split(','))
57 else:
58 run(control_file, None)