blob: 43e859f03d844fbc75d7815f2d4a2aa0c20a3d17 [file] [log] [blame]
mblighb7dcc7f2008-06-02 19:34:25 +00001__author__ = "raphtee@google.com (Travis Miller)"
2
3
mbligha6f13082008-06-05 23:53:46 +00004import os, sys, getopt, optparse
mblighb7dcc7f2008-06-02 19:34:25 +00005
6
7class base_autoserv_parser(object):
8 """Custom command-line options parser for autoserv.
9
10 We can't use the general getopt methods here, as there will be unknown
11 extra arguments that we pass down into the control file instead.
12 Thus we process the arguments by hand, for which we are duly repentant.
13 Making a single function here just makes it harder to read. Suck it up.
14 """
15 def __init__(self):
16 self.args = sys.argv[1:]
mbligha6f13082008-06-05 23:53:46 +000017 self.parser = optparse.OptionParser()
18 self.setup_options()
19 self.parse_args()
20
21
22 def setup_options(self):
23 self.parser.add_option("-m", action="store", type="string",
24 dest="machines",
25 help="list of machines")
26 self.parser.add_option("-M", action="store", type="string",
27 dest="machines_file",
28 help="list of machines from file")
29 self.parser.add_option("-c", action="store_true",
30 dest="client", default=False,
31 help="control file is client side")
32 self.parser.add_option("-r", action="store", type="string",
33 dest="results", default='.',
34 help="specify results directory")
35 self.parser.add_option("-l", action="store", type="string",
36 dest="label", default='',
37 help="label for the job")
38 self.parser.add_option("-u", action="store", type="string",
39 dest="user",
40 default=os.environ.get('USER'),
41 help="username for the job")
42 self.parser.add_option("-P", action="store", type="string",
43 dest="parse_job",
44 default='',
45 help="parse the results of the job")
46 self.parser.add_option("-i", action="store_true",
47 dest="install_before", default=False,
48 help="reinstall machines before running the job")
49 self.parser.add_option("-I", action="store_true",
50 dest="install_after", default=False,
51 help="reinstall machines after running the job")
52 self.parser.add_option("-b", action="store_true",
53 dest="reboot", default=False,
54 help="reboot all machines after job")
55 self.parser.add_option("-v", action="store_true",
56 dest="verify", default=False,
57 help="verify the machines only")
58 self.parser.add_option("-R", action="store_true",
59 dest="repair", default=False,
60 help="repair the machines")
61 self.parser.add_option("-n", action="store_true",
62 dest="no_tee", default=False,
63 help="no teeing the status to stdout/err")
64 self.parser.add_option("-p", action="store_true",
65 dest="write_pidfile", default=False,
66 help="write pidfile (.autoserv_execute)")
67 self.parser.add_option("--ssh-user", action="store",
68 type="string", dest="ssh_user",
69 default="root",
70 help=("specify the user for ssh"
71 "connections"))
72 self.parser.add_option("--ssh-port", action="store",
73 type="int", dest="ssh_port",
74 default=22,
75 help=("specify the port to use for "
76 "ssh connections"))
77 self.parser.add_option("--ssh-pass", action="store",
78 type="string", dest="ssh_pass",
79 default="",
80 help=("specify the password to use "
81 "for ssh connections"))
mblighb7dcc7f2008-06-02 19:34:25 +000082
83
mbligha6f13082008-06-05 23:53:46 +000084 def parse_args(self):
85 (self.options, self.args) = self.parser.parse_args()
mblighb7dcc7f2008-06-02 19:34:25 +000086
87
88
89try:
90 from autotest_lib.server.site_autoserv_parser \
91 import site_autoserv_parser
92except ImportError:
93 class site_autoserv_parser(base_autoserv_parser):
94 pass
95
96
97class autoserv_parser(site_autoserv_parser):
98 pass
99
100
101# create the one and only one instance of autoserv_parser
102autoserv_parser = autoserv_parser()