| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2007 Google Inc. Released under the GPL v2 |
| 4 | |
| mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 5 | """ |
| 6 | Run an autoserv control file |
| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 7 | |
| 8 | TODO(poirier): add a singleton logger |
| 9 | TODO(poirier): maybe change the name "get_file" to "receive_file" ? |
| mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 10 | TODO(poirier): change get(), send_file(), get_file() to consistantly recognize |
| 11 | paths that start with '~' as refering to the home directory |
| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 12 | """ |
| 13 | |
| mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 14 | __author__ = """ |
| 15 | mbligh@google.com (Martin J. Bligh), |
| 16 | poirier@google.com (Benjamin Poirier), |
| 17 | stutsman@google.com (Ryan Stutsman) |
| 18 | """ |
| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 19 | |
| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 20 | import sys |
| 21 | import optparse |
| 22 | |
| 23 | |
| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 24 | def parse_args(): |
| mbligh | 29aa970 | 2007-08-09 22:41:43 +0000 | [diff] [blame] | 25 | 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() |
| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 29 | return (options, arg) |
| 30 | |
| 31 | |
| mbligh | 29aa970 | 2007-08-09 22:41:43 +0000 | [diff] [blame] | 32 | preamble = """\ |
| 33 | import os, sys |
| 34 | |
| 35 | import errors, hosts, autotest, kvm |
| 36 | import source_kernel, rpm_kernel, deb_kernel |
| 37 | from subcommand import * |
| 38 | |
| mbligh | 03dd079 | 2007-08-28 10:26:46 +0000 | [diff] [blame^] | 39 | from utils import run, get_tmp_dir, sh_escape |
| mbligh | 29aa970 | 2007-08-09 22:41:43 +0000 | [diff] [blame] | 40 | """ |
| 41 | |
| 42 | def run(control_file, machines): |
| 43 | namespace = dict({'machines': machines}) |
| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 44 | |
| mbligh | 29aa970 | 2007-08-09 22:41:43 +0000 | [diff] [blame] | 45 | exec(preamble, namespace, namespace) |
| 46 | execfile(control_file, namespace, namespace) |
| mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | if __name__ == "__main__": |
| 50 | (options, args) = parse_args() |
| 51 | if len(args) != 1: |
| 52 | parser.error("program takes one argument") |
| 53 | sys.exit(1) |
| mbligh | 29aa970 | 2007-08-09 22:41:43 +0000 | [diff] [blame] | 54 | control_file = args[0] |
| 55 | if options.machines: |
| 56 | run(control_file, options.machines.split(',')) |
| 57 | else: |
| 58 | run(control_file, None) |