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

Side by Side Diff: native_client_sdk/src/tools/getos.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 """Determine OS and various other system properties. 6 """Determine OS and various other system properties.
7 7
8 Determine the name of the platform used and other system properties such as 8 Determine the name of the platform used and other system properties such as
9 the location of Chrome. This is used, for example, to determine the correct 9 the location of Chrome. This is used, for example, to determine the correct
10 Toolchain to invoke. 10 Toolchain to invoke.
11 """ 11 """
12 12
13 import optparse 13 import argparse
14 import os 14 import os
15 import re 15 import re
16 import subprocess 16 import subprocess
17 import sys 17 import sys
18 18
19 import oshelpers 19 import oshelpers
20 20
21 21
22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
23 CHROME_DEFAULT_PATH = { 23 CHROME_DEFAULT_PATH = {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 Raises: 209 Raises:
210 Error: The SDK version is older than required_version. 210 Error: The SDK version is older than required_version.
211 """ 211 """
212 version = GetSDKVersion()[:2] 212 version = GetSDKVersion()[:2]
213 if version < required_version: 213 if version < required_version:
214 raise Error("SDK version too old (current: %d.%d, required: %d.%d)" 214 raise Error("SDK version too old (current: %d.%d, required: %d.%d)"
215 % (version[0], version[1], required_version[0], required_version[1])) 215 % (version[0], version[1], required_version[0], required_version[1]))
216 216
217 217
218 def main(args): 218 def main(args):
219 parser = optparse.OptionParser() 219 parser = argparse.ArgumentParser()
220 parser.add_option('--arch', action='store_true', 220 parser.add_argument('--arch', action='store_true',
221 help='Print architecture of current machine (x86_32, x86_64 or arm).') 221 help='Print architecture of current machine (x86_32, x86_64 or arm).')
222 parser.add_option('--chrome', action='store_true', 222 parser.add_argument('--chrome', action='store_true',
223 help='Print the path chrome (by first looking in $CHROME_PATH and ' 223 help='Print the path chrome (by first looking in $CHROME_PATH and '
224 'then $PATH).') 224 'then $PATH).')
225 parser.add_option('--nacl-arch', action='store_true', 225 parser.add_argument('--nacl-arch', action='store_true',
226 help='Print architecture used by NaCl on the current machine.') 226 help='Print architecture used by NaCl on the current machine.')
227 parser.add_option('--sdk-version', action='store_true', 227 parser.add_argument('--sdk-version', action='store_true',
228 help='Print major version of the NaCl SDK.') 228 help='Print major version of the NaCl SDK.')
229 parser.add_option('--sdk-revision', action='store_true', 229 parser.add_argument('--sdk-revision', action='store_true',
230 help='Print revision number of the NaCl SDK.') 230 help='Print revision number of the NaCl SDK.')
231 parser.add_option('--sdk-commit-position', action='store_true', 231 parser.add_argument('--sdk-commit-position', action='store_true',
232 help='Print commit position of the NaCl SDK.') 232 help='Print commit position of the NaCl SDK.')
233 parser.add_option('--check-version', 233 parser.add_argument('--check-version',
234 metavar='MAJOR.POSITION', 234 metavar='MAJOR.POSITION',
235 help='Check that the SDK version is at least as great as the ' 235 help='Check that the SDK version is at least as great as the '
236 'version passed in. MAJOR is the major version number and POSITION ' 236 'version passed in. MAJOR is the major version number and POSITION '
237 'is the Cr-Commit-Position number.') 237 'is the Cr-Commit-Position number.')
238 238
239 options, _ = parser.parse_args(args) 239 options, _ = parser.parse_args(args)
binji 2014/11/13 23:57:04 fix
Sam Clegg 2014/11/30 17:55:13 Done.
240 240
241 platform = GetPlatform() 241 platform = GetPlatform()
242 242
243 if len(args) > 1: 243 if len(args) > 1:
244 parser.error('Only one option can be specified at a time.') 244 parser.error('Only one option can be specified at a time.')
245 245
246 if not args: 246 if not args:
247 print platform 247 print platform
248 return 0 248 return 0
249 249
(...skipping 18 matching lines...) Expand all
268 print out 268 print out
269 return 0 269 return 0
270 270
271 271
272 if __name__ == '__main__': 272 if __name__ == '__main__':
273 try: 273 try:
274 sys.exit(main(sys.argv[1:])) 274 sys.exit(main(sys.argv[1:]))
275 except Error as e: 275 except Error as e:
276 sys.stderr.write(str(e) + '\n') 276 sys.stderr.write(str(e) + '\n')
277 sys.exit(1) 277 sys.exit(1)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698