mbligh | 6203ace | 2007-10-04 21:54:24 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2007 Google Inc. Released under the GPL v2 |
| 4 | |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 5 | """ |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 6 | Run an control file through the server side engine |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 7 | """ |
| 8 | |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 9 | __author__ = """\ |
| 10 | mbligh@google.com (Martin J. Bligh) |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 11 | """ |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 12 | |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 13 | import sys, os, re, server_job |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 14 | |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 15 | usage = """\ |
| 16 | usage: autoserv |
| 17 | [-b] # reboot all specified machines after the job |
| 18 | [-c] # control file is a client side control |
| 19 | [-r resultsdir] # specify results directory (default '.') |
mbligh | 18420c2 | 2007-10-16 22:27:14 +0000 | [diff] [blame] | 20 | [-l label] # label for the job (arbitrary string) |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 21 | [-u user] # username for the job (email address) |
| 22 | [-m machine,[machine,...]] # list of machines to pass to control file |
| 23 | <control file> # name of the control file to run |
| 24 | [args ...] # args to pass through to the control file |
mbligh | 29aa970 | 2007-08-09 22:41:43 +0000 | [diff] [blame] | 25 | """ |
| 26 | |
mbligh | 9d1c730 | 2007-10-07 18:53:13 +0000 | [diff] [blame] | 27 | args = sys.argv[1:] |
| 28 | |
mbligh | 9d1c730 | 2007-10-07 18:53:13 +0000 | [diff] [blame] | 29 | # We can't use the general getopt methods here, as there will be unknown |
| 30 | # extra arguments that we pass down into the control file instead. |
| 31 | # Thus we process the arguments by hand, for which we are duly repentant. |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 32 | # Making a single function here just makes it harder to read. Suck it up. |
| 33 | def parse_opts(flag): |
| 34 | if args.count(flag): |
| 35 | idx = args.index(flag) |
| 36 | args[idx : idx+1] = [] |
| 37 | return True |
| 38 | else: |
| 39 | return False |
mbligh | c99add6 | 2007-09-27 17:02:58 +0000 | [diff] [blame] | 40 | |
mbligh | c99add6 | 2007-09-27 17:02:58 +0000 | [diff] [blame] | 41 | |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 42 | def parse_opts_param(flag, default = None, split = False): |
| 43 | if args.count(flag): |
| 44 | idx = args.index(flag) |
| 45 | ret = args[idx+1] |
| 46 | args[idx : idx+2] = [] |
| 47 | if split: |
| 48 | return ret.split(split) |
| 49 | else: |
| 50 | return ret |
| 51 | else: |
| 52 | return default |
| 53 | |
| 54 | |
| 55 | machines = parse_opts_param('-m', None, split = ',') |
| 56 | results = parse_opts_param('-r', os.path.abspath('.')) |
mbligh | 18420c2 | 2007-10-16 22:27:14 +0000 | [diff] [blame] | 57 | label = parse_opts_param('-l', '') |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 58 | user = parse_opts_param('-u', 'anonymous') |
| 59 | client = parse_opts('-c') |
| 60 | reboot = parse_opts('-b') |
mbligh | cc2c3a6 | 2007-10-12 00:34:31 +0000 | [diff] [blame] | 61 | |
mbligh | 9d1c730 | 2007-10-07 18:53:13 +0000 | [diff] [blame] | 62 | if len(args) < 1: |
mbligh | 4ef8623 | 2007-10-23 00:09:53 +0000 | [diff] [blame^] | 63 | print usage |
| 64 | sys.exit(-1) |
mbligh | c99add6 | 2007-09-27 17:02:58 +0000 | [diff] [blame] | 65 | |
mbligh | 18420c2 | 2007-10-16 22:27:14 +0000 | [diff] [blame] | 66 | job = server_job.server_job(args[0], args[1:], results, label, user, client) |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 67 | job.run(machines, reboot) |