Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: client/auth.py

Issue 1233303003: Migrate and merge logging_utils from swarming_bot into client/utils. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: Changed formatter Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Swarming Authors. All rights reserved. 2 # Copyright 2013 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 that 3 # Use of this source code is governed under the Apache License, Version 2.0 that
4 # can be found in the LICENSE file. 4 # can be found in the LICENSE file.
5 5
6 """Client tool to perform various authentication related tasks.""" 6 """Client tool to perform various authentication related tasks."""
7 7
8 __version__ = '0.4' 8 __version__ = '0.4'
9 9
10 import logging 10 import logging
11 import optparse 11 import optparse
12 import sys 12 import sys
13 13
14 from third_party import colorama 14 from third_party import colorama
15 from third_party.depot_tools import fix_encoding 15 from third_party.depot_tools import fix_encoding
16 from third_party.depot_tools import subcommand 16 from third_party.depot_tools import subcommand
17 17
18 from utils import logging_utils
18 from utils import on_error 19 from utils import on_error
19 from utils import net 20 from utils import net
20 from utils import oauth 21 from utils import oauth
21 from utils import tools 22 from utils import tools
22 23
23 24
24 class AuthServiceError(Exception): 25 class AuthServiceError(Exception):
25 """Unexpected response from authentication service.""" 26 """Unexpected response from authentication service."""
26 27
27 28
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 def CMDcheck(parser, args): 130 def CMDcheck(parser, args):
130 """Shows identity associated with currently cached auth token/cookie.""" 131 """Shows identity associated with currently cached auth token/cookie."""
131 (options, args) = parser.parse_args(args) 132 (options, args) = parser.parse_args(args)
132 process_auth_options(parser, options) 133 process_auth_options(parser, options)
133 service = AuthService(options.service) 134 service = AuthService(options.service)
134 service.login(False) 135 service.login(False)
135 print service.get_current_identity() 136 print service.get_current_identity()
136 return 0 137 return 0
137 138
138 139
139 class OptionParserAuth(tools.OptionParserWithLogging): 140 class OptionParserAuth(logging_utils.OptionParserWithLogging):
140 def __init__(self, **kwargs): 141 def __init__(self, **kwargs):
141 tools.OptionParserWithLogging.__init__(self, prog='auth.py', **kwargs) 142 logging_utils.OptionParserWithLogging.__init__(
143 self, prog='auth.py', **kwargs)
142 self.server_group = tools.optparse.OptionGroup(self, 'Server') 144 self.server_group = tools.optparse.OptionGroup(self, 'Server')
143 self.server_group.add_option( 145 self.server_group.add_option(
144 '-S', '--service', 146 '-S', '--service',
145 metavar='URL', default='', 147 metavar='URL', default='',
146 help='Service to use') 148 help='Service to use')
147 self.add_option_group(self.server_group) 149 self.add_option_group(self.server_group)
148 add_auth_options(self) 150 add_auth_options(self)
149 151
150 def parse_args(self, *args, **kwargs): 152 def parse_args(self, *args, **kwargs):
151 options, args = tools.OptionParserWithLogging.parse_args( 153 options, args = logging_utils.OptionParserWithLogging.parse_args(
152 self, *args, **kwargs) 154 self, *args, **kwargs)
153 options.service = options.service.rstrip('/') 155 options.service = options.service.rstrip('/')
154 if not options.service: 156 if not options.service:
155 self.error('--service is required.') 157 self.error('--service is required.')
156 on_error.report_on_exception_exit(options.service) 158 on_error.report_on_exception_exit(options.service)
157 return options, args 159 return options, args
158 160
159 161
160 def main(args): 162 def main(args):
161 dispatcher = subcommand.CommandDispatcher(__name__) 163 dispatcher = subcommand.CommandDispatcher(__name__)
162 return dispatcher.execute(OptionParserAuth(version=__version__), args) 164 return dispatcher.execute(OptionParserAuth(version=__version__), args)
163 165
164 166
165 if __name__ == '__main__': 167 if __name__ == '__main__':
166 fix_encoding.fix_encoding() 168 fix_encoding.fix_encoding()
167 tools.disable_buffering() 169 tools.disable_buffering()
168 colorama.init() 170 colorama.init()
169 sys.exit(main(sys.argv[1:])) 171 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698