mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 1 | __author__ = "raphtee@google.com (Travis Miller)" |
| 2 | |
| 3 | |
| 4 | import sys |
| 5 | |
| 6 | |
| 7 | usage = """\ |
| 8 | usage: 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 | |
| 29 | class 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: |
mbligh | a5b607f | 2008-06-02 19:35:37 +0000 | [diff] [blame] | 40 | print self.get_usage() |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 41 | sys.exit(1) |
| 42 | if self.parse_opts('-h') or self.parse_opts('--help'): |
mbligh | a5b607f | 2008-06-02 19:35:37 +0000 | [diff] [blame] | 43 | print self.get_usage() |
mbligh | b7dcc7f | 2008-06-02 19:34:25 +0000 | [diff] [blame] | 44 | 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 | |
| 74 | try: |
| 75 | from autotest_lib.server.site_autoserv_parser \ |
| 76 | import site_autoserv_parser |
| 77 | except ImportError: |
| 78 | class site_autoserv_parser(base_autoserv_parser): |
| 79 | pass |
| 80 | |
| 81 | |
| 82 | class autoserv_parser(site_autoserv_parser): |
| 83 | pass |
| 84 | |
| 85 | |
| 86 | # create the one and only one instance of autoserv_parser |
| 87 | autoserv_parser = autoserv_parser() |