OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 # | 6 # |
7 # A python wrapper to call autotest ebuild. | 7 # A python wrapper to call autotest ebuild. |
8 | 8 |
9 import commands, logging, optparse, os, subprocess, sys | 9 import commands, logging, optparse, os, subprocess, sys |
10 | 10 |
11 | 11 |
12 def run(cmd): | 12 def run(cmd): |
13 return subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr) | 13 return subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr) |
14 | 14 |
15 | 15 |
16 class MyOptionPaser(optparse.OptionParser): | 16 class MyOptionParser(optparse.OptionParser): |
17 """Override python's builtin OptionParser to accept any undefined args.""" | 17 """Override python's builtin OptionParser to accept any undefined args.""" |
18 | 18 |
19 help = False | 19 help = False |
20 | 20 |
21 def _process_args(self, largs, rargs, values): | 21 def _process_args(self, largs, rargs, values): |
22 # see /usr/lib64/python2.6/optparse.py line 1414-1463 | 22 # see /usr/lib64/python2.6/optparse.py line 1414-1463 |
23 while rargs: | 23 while rargs: |
24 arg = rargs[0] | 24 arg = rargs[0] |
25 # We handle bare "--" explicitly, and bare "-" is handled by the | 25 # We handle bare "--" explicitly, and bare "-" is handled by the |
26 # standard arg handler since the short arg case ensures that the | 26 # standard arg handler since the short arg case ensures that the |
(...skipping 15 matching lines...) Expand all Loading... |
42 except optparse.BadOptionError: | 42 except optparse.BadOptionError: |
43 largs.append(arg) | 43 largs.append(arg) |
44 elif self.allow_interspersed_args: | 44 elif self.allow_interspersed_args: |
45 largs.append(arg) | 45 largs.append(arg) |
46 del rargs[0] | 46 del rargs[0] |
47 else: | 47 else: |
48 return # stop now, leave this arg in rargs | 48 return # stop now, leave this arg in rargs |
49 | 49 |
50 def print_help(self, file=None): | 50 def print_help(self, file=None): |
51 optparse.OptionParser.print_help(self, file) | 51 optparse.OptionParser.print_help(self, file) |
52 MyOptionPaser.help = True | 52 MyOptionParser.help = True |
53 | 53 |
54 | 54 |
55 parser = MyOptionPaser() | 55 parser = MyOptionParser() |
56 parser.allow_interspersed_args = True | 56 parser.allow_interspersed_args = True |
57 | 57 |
58 DEFAULT_BOARD = os.environ.get('DEFAULT_BOARD', '') | 58 DEFAULT_BOARD = os.environ.get('DEFAULT_BOARD', '') |
59 | 59 |
60 parser.add_option('--autox', dest='autox', action='store_true', | 60 parser.add_option('--autox', dest='autox', action='store_true', |
61 default=True, | 61 default=True, |
62 help='Build autox along with autotest [default].') | 62 help='Build autox along with autotest [default].') |
63 parser.add_option('--noautox', dest='autox', action='store_false', | 63 parser.add_option('--noautox', dest='autox', action='store_false', |
64 help='Don\'t build autox along with autotest.') | 64 help='Don\'t build autox along with autotest.') |
65 parser.add_option('--board', dest='board', action='store', | 65 parser.add_option('--board', dest='board', action='store', |
(...skipping 22 matching lines...) Expand all Loading... |
88 pass | 88 pass |
89 | 89 |
90 sys_exit = sys.exit | 90 sys_exit = sys.exit |
91 sys.exit = nop | 91 sys.exit = nop |
92 options, args = parser.parse_args() | 92 options, args = parser.parse_args() |
93 sys.exit = sys_exit | 93 sys.exit = sys_exit |
94 | 94 |
95 if not args and not options.build: | 95 if not args and not options.build: |
96 parser.print_help() | 96 parser.print_help() |
97 | 97 |
98 if MyOptionPaser.help: | 98 if MyOptionParser.help: |
99 if options.build: | 99 if options.build: |
100 print | 100 print |
101 print 'Options inherited from autotest_client, which is used in build', | 101 print 'Options inherited from autotest_client, which is used in build', |
102 print 'only mode.' | 102 print 'only mode.' |
103 run([AUTOTEST_CLIENT, '--help']) | 103 run([AUTOTEST_CLIENT, '--help']) |
104 else: | 104 else: |
105 print | 105 print |
106 print 'Options inherited from autoserv:' | 106 print 'Options inherited from autoserv:' |
107 run([AUTOSERV, '--help']) | 107 run([AUTOSERV, '--help']) |
108 sys.exit(0) | 108 sys.exit(0) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 die(common_sh, 'build_autotest failed.') | 213 die(common_sh, 'build_autotest failed.') |
214 else: | 214 else: |
215 ssh_key_file = os.path.join(os.path.dirname(me), | 215 ssh_key_file = os.path.join(os.path.dirname(me), |
216 'mod_for_test_scripts/ssh_keys/testing_rsa') | 216 'mod_for_test_scripts/ssh_keys/testing_rsa') |
217 os.chmod(ssh_key_file, 0400) | 217 os.chmod(ssh_key_file, 0400) |
218 run_autoserv(options.board, args) | 218 run_autoserv(options.board, args) |
219 | 219 |
220 | 220 |
221 if __name__ == '__main__': | 221 if __name__ == '__main__': |
222 main() | 222 main() |
OLD | NEW |