OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Access the commit queue from the command line. | 6 """Access the commit queue from the command line. |
7 """ | 7 """ |
8 | 8 |
9 __version__ = '0.1' | 9 __version__ = '0.1' |
10 | 10 |
11 import functools | 11 import functools |
12 import logging | 12 import logging |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
15 import sys | 15 import sys |
16 import urllib2 | 16 import urllib2 |
17 | 17 |
18 import breakpad # pylint: disable=W0611 | 18 import breakpad # pylint: disable=W0611 |
19 | 19 |
| 20 import auth |
20 import fix_encoding | 21 import fix_encoding |
21 import rietveld | 22 import rietveld |
22 | 23 |
23 | 24 |
24 def usage(more): | 25 def usage(more): |
25 def hook(fn): | 26 def hook(fn): |
26 fn.func_usage_more = more | 27 fn.func_usage_more = more |
27 return fn | 28 return fn |
28 return hook | 29 return hook |
29 | 30 |
30 | 31 |
31 def need_issue(fn): | 32 def need_issue(fn): |
32 """Post-parse args to create a Rietveld object.""" | 33 """Post-parse args to create a Rietveld object.""" |
33 @functools.wraps(fn) | 34 @functools.wraps(fn) |
34 def hook(parser, args, *extra_args, **kwargs): | 35 def hook(parser, args, *extra_args, **kwargs): |
35 old_parse_args = parser.parse_args | 36 old_parse_args = parser.parse_args |
36 | 37 |
37 def new_parse_args(args=None, values=None): | 38 def new_parse_args(args=None, values=None): |
38 options, args = old_parse_args(args, values) | 39 options, args = old_parse_args(args, values) |
| 40 auth_config = auth.extract_auth_config_from_options(options) |
39 if not options.issue: | 41 if not options.issue: |
40 parser.error('Require --issue') | 42 parser.error('Require --issue') |
41 obj = rietveld.Rietveld(options.server, options.user, None) | 43 obj = rietveld.Rietveld(options.server, auth_config, options.user) |
42 return options, args, obj | 44 return options, args, obj |
43 | 45 |
44 parser.parse_args = new_parse_args | 46 parser.parse_args = new_parse_args |
45 | 47 |
46 parser.add_option( | 48 parser.add_option( |
47 '-u', '--user', | 49 '-u', '--user', |
48 metavar='U', | 50 metavar='U', |
49 default=os.environ.get('EMAIL_ADDRESS', None), | 51 default=os.environ.get('EMAIL_ADDRESS', None), |
50 help='Email address, default: %default') | 52 help='Email address, default: %default') |
51 parser.add_option( | 53 parser.add_option( |
52 '-i', '--issue', | 54 '-i', '--issue', |
53 metavar='I', | 55 metavar='I', |
54 type='int', | 56 type='int', |
55 help='Rietveld issue number') | 57 help='Rietveld issue number') |
56 parser.add_option( | 58 parser.add_option( |
57 '-s', | 59 '-s', |
58 '--server', | 60 '--server', |
59 metavar='S', | 61 metavar='S', |
60 default='http://codereview.chromium.org', | 62 default='http://codereview.chromium.org', |
61 help='Rietveld server, default: %default') | 63 help='Rietveld server, default: %default') |
| 64 auth.add_auth_options(parser) |
62 | 65 |
63 # Call the original function with the modified parser. | 66 # Call the original function with the modified parser. |
64 return fn(parser, args, *extra_args, **kwargs) | 67 return fn(parser, args, *extra_args, **kwargs) |
65 | 68 |
66 hook.func_usage_more = '[options]' | 69 hook.func_usage_more = '[options]' |
67 return hook | 70 return hook |
68 | 71 |
69 | 72 |
70 def set_commit(obj, issue, flag): | 73 def set_commit(obj, issue, flag): |
71 """Sets the commit bit flag on an issue.""" | 74 """Sets the commit bit flag on an issue.""" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 return CMDhelp(parser, args) | 182 return CMDhelp(parser, args) |
180 | 183 |
181 | 184 |
182 if __name__ == "__main__": | 185 if __name__ == "__main__": |
183 fix_encoding.fix_encoding() | 186 fix_encoding.fix_encoding() |
184 try: | 187 try: |
185 sys.exit(main()) | 188 sys.exit(main()) |
186 except KeyboardInterrupt: | 189 except KeyboardInterrupt: |
187 sys.stderr.write('interrupted\n') | 190 sys.stderr.write('interrupted\n') |
188 sys.exit(1) | 191 sys.exit(1) |
OLD | NEW |