blob: 509444ddff1609b810e25e991681ce58af0ff2f7 [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"""
mblighf1c52842007-10-16 15:21:38 +00006Run an control file through the server side engine
mblighdcd57a82007-07-11 23:06:47 +00007"""
8
mblighf1c52842007-10-16 15:21:38 +00009__author__ = """\
10mbligh@google.com (Martin J. Bligh)
mblighc8949b82007-07-23 16:33:58 +000011"""
mblighdcd57a82007-07-11 23:06:47 +000012
mblighf1c52842007-10-16 15:21:38 +000013import sys, os, re, server_job
mblighdcd57a82007-07-11 23:06:47 +000014
mblighf1c52842007-10-16 15:21:38 +000015usage = """\
16usage: 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 '.')
mbligh18420c22007-10-16 22:27:14 +000020 [-l label] # label for the job (arbitrary string)
mblighf1c52842007-10-16 15:21:38 +000021 [-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
mbligh29aa9702007-08-09 22:41:43 +000025"""
26
mbligh9d1c7302007-10-07 18:53:13 +000027args = sys.argv[1:]
28
mbligh9d1c7302007-10-07 18:53:13 +000029# 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.
mblighf1c52842007-10-16 15:21:38 +000032# Making a single function here just makes it harder to read. Suck it up.
33def 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
mblighc99add62007-09-27 17:02:58 +000040
mblighc99add62007-09-27 17:02:58 +000041
mblighf1c52842007-10-16 15:21:38 +000042def 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
55machines = parse_opts_param('-m', None, split = ',')
56results = parse_opts_param('-r', os.path.abspath('.'))
mbligh18420c22007-10-16 22:27:14 +000057label = parse_opts_param('-l', '')
mblighf1c52842007-10-16 15:21:38 +000058user = parse_opts_param('-u', 'anonymous')
59client = parse_opts('-c')
60reboot = parse_opts('-b')
mblighcc2c3a62007-10-12 00:34:31 +000061
mbligh9d1c7302007-10-07 18:53:13 +000062if len(args) < 1:
mbligh4ef86232007-10-23 00:09:53 +000063 print usage
64 sys.exit(-1)
mblighc99add62007-09-27 17:02:58 +000065
mbligh18420c22007-10-16 22:27:14 +000066job = server_job.server_job(args[0], args[1:], results, label, user, client)
mblighf1c52842007-10-16 15:21:38 +000067job.run(machines, reboot)