blob: ad143529b3159793e4713070c96b6a4bd635f359 [file] [log] [blame]
mblighb7dcc7f2008-06-02 19:34:25 +00001__author__ = "raphtee@google.com (Travis Miller)"
2
3
4import sys
5
6
7usage = """\
8usage: autoserv
9 [-h, --help] # This help message
10 [-m machine,[machine,...]] # list of machines to pass to control file
11 [-M machines_file] # list of machines (from a file)
12 [-c] # control file is a client side control
13 [-r resultsdir] # specify results directory (default '.')
14 [-i] # reinstall machines before running the job
15 [-I] # reinstall machines after running the job
16 [-b] # reboot all specified machines after the job
17 [-l label] # label for the job (arbitrary string)
18 [-u user] # username for the job (email address)
19 [-v] # verify the machines only
20 [-R] # repair the machines
21 [-n] # no teeing the status to stdout/stderr
22 [-p] # write pidfile (.autoserv_execute)
23 [-P jobname] # parse the results of the job
24 <control file> # name of the control file to run
25 [args ...] # args to pass through to the control file
26"""
27
28
29class base_autoserv_parser(object):
30 """Custom command-line options parser for autoserv.
31
32 We can't use the general getopt methods here, as there will be unknown
33 extra arguments that we pass down into the control file instead.
34 Thus we process the arguments by hand, for which we are duly repentant.
35 Making a single function here just makes it harder to read. Suck it up.
36 """
37 def __init__(self):
38 self.args = sys.argv[1:]
39 if len(self.args) == 0:
mbligha5b607f2008-06-02 19:35:37 +000040 print self.get_usage()
mblighb7dcc7f2008-06-02 19:34:25 +000041 sys.exit(1)
42 if self.parse_opts('-h') or self.parse_opts('--help'):
mbligha5b607f2008-06-02 19:35:37 +000043 print self.get_usage()
mblighb7dcc7f2008-06-02 19:34:25 +000044 sys.exit(0)
45
46
47 def get_usage(self):
48 return usage
49
50
51 def parse_opts(self, flag):
52 if self.args.count(flag):
53 idx = self.args.index(flag)
54 self.args[idx : idx+1] = []
55 return True
56 else:
57 return False
58
59
60 def parse_opts_param(self, flag, default = None, split = False):
61 if self.args.count(flag):
62 idx = self.args.index(flag)
63 ret = self.args[idx+1]
64 self.args[idx : idx+2] = []
65 if split:
66 return ret.split(split)
67 else:
68 return ret
69 else:
70 return default
71
72
73
74try:
75 from autotest_lib.server.site_autoserv_parser \
76 import site_autoserv_parser
77except ImportError:
78 class site_autoserv_parser(base_autoserv_parser):
79 pass
80
81
82class autoserv_parser(site_autoserv_parser):
83 pass
84
85
86# create the one and only one instance of autoserv_parser
87autoserv_parser = autoserv_parser()