OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 """Manages cached OAuth2 tokens used by other depot_tools scripts. | 6 """Manages cached OAuth2 tokens used by other depot_tools scripts. |
7 | 7 |
8 Usage: | 8 Usage: |
9 depot-tools-auth login codereview.chromium.org | 9 depot-tools-auth login codereview.chromium.org |
10 depot-tools-auth info codereview.chromium.org | 10 depot-tools-auth info codereview.chromium.org |
11 depot-tools-auth logout codereview.chromium.org | 11 depot-tools-auth logout codereview.chromium.org |
12 """ | 12 """ |
13 | 13 |
14 import logging | 14 import logging |
15 import optparse | 15 import optparse |
16 import sys | 16 import sys |
17 import os | 17 import os |
18 | 18 |
19 from third_party import colorama | |
20 | |
21 import auth | 19 import auth |
| 20 import setup_color |
22 import subcommand | 21 import subcommand |
23 | 22 |
24 __version__ = '1.0' | 23 __version__ = '1.0' |
25 | 24 |
26 | 25 |
27 @subcommand.usage('<hostname>') | 26 @subcommand.usage('<hostname>') |
28 def CMDlogin(parser, args): | 27 def CMDlogin(parser, args): |
29 """Performs interactive login and caches authentication token.""" | 28 """Performs interactive login and caches authentication token.""" |
30 # Forcefully relogin, revoking previous token. | 29 # Forcefully relogin, revoking previous token. |
31 hostname, authenticator = parser.parse_args(args) | 30 hostname, authenticator = parser.parse_args(args) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 def main(argv): | 87 def main(argv): |
89 dispatcher = subcommand.CommandDispatcher(__name__) | 88 dispatcher = subcommand.CommandDispatcher(__name__) |
90 try: | 89 try: |
91 return dispatcher.execute(OptionParser(), argv) | 90 return dispatcher.execute(OptionParser(), argv) |
92 except auth.AuthenticationError as e: | 91 except auth.AuthenticationError as e: |
93 print >> sys.stderr, e | 92 print >> sys.stderr, e |
94 return 1 | 93 return 1 |
95 | 94 |
96 | 95 |
97 if __name__ == '__main__': | 96 if __name__ == '__main__': |
98 colorama.init(wrap="TERM" not in os.environ) | 97 setup_color.init() |
99 try: | 98 try: |
100 sys.exit(main(sys.argv[1:])) | 99 sys.exit(main(sys.argv[1:])) |
101 except KeyboardInterrupt: | 100 except KeyboardInterrupt: |
102 sys.stderr.write('interrupted\n') | 101 sys.stderr.write('interrupted\n') |
103 sys.exit(1) | 102 sys.exit(1) |
OLD | NEW |