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

Side by Side Diff: native_client_sdk/src/tools/fix_manifest.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) 2014 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2014 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 # Disable the lint error for too-long lines for the URL below. 6 # Disable the lint error for too-long lines for the URL below.
7 # pylint: disable=C0301 7 # pylint: disable=C0301
8 8
9 """Fix Chrome App manifest.json files for use with multi-platform zip files. 9 """Fix Chrome App manifest.json files for use with multi-platform zip files.
10 10
(...skipping 18 matching lines...) Expand all
29 "platforms": [ 29 "platforms": [
30 { 30 {
31 "nacl_arch": "x86-64", 31 "nacl_arch": "x86-64",
32 "sub_package_path": "<toolchain>/<config>/_platform_specific/x86-64/" 32 "sub_package_path": "<toolchain>/<config>/_platform_specific/x86-64/"
33 }, 33 },
34 ... 34 ...
35 """ 35 """
36 36
37 import collections 37 import collections
38 import json 38 import json
39 import optparse 39 import argparse
binji 2014/11/13 23:57:03 sort
Sam Clegg 2014/11/30 17:55:12 Done.
40 import os 40 import os
41 import sys 41 import sys
42 42
43 if sys.version_info < (2, 6, 0): 43 if sys.version_info < (2, 6, 0):
binji 2014/11/13 23:57:03 2.7
Sam Clegg 2014/11/30 17:55:13 Separate CL
44 sys.stderr.write("python 2.6 or later is required run this script\n") 44 sys.stderr.write("python 2.6 or later is required run this script\n")
45 sys.exit(1) 45 sys.exit(1)
46 46
47 47
48 class Error(Exception): 48 class Error(Exception):
49 """Local Error class for this file.""" 49 """Local Error class for this file."""
50 pass 50 pass
51 51
52 52
53 def Trace(msg): 53 def Trace(msg):
54 if Trace.verbose: 54 if Trace.verbose:
55 sys.stderr.write(str(msg) + '\n') 55 sys.stderr.write(str(msg) + '\n')
56 56
57 Trace.verbose = False 57 Trace.verbose = False
58 58
59 59
60 def main(argv): 60 def main(argv):
61 parser = optparse.OptionParser( 61 parser = argparse.ArgumentParser(
62 usage='Usage: %prog [options] manifest.json', description=__doc__) 62 usage='Usage: %prog [options] manifest.json', description=__doc__)
binji 2014/11/13 23:57:03 remove usage
Sam Clegg 2014/11/30 17:55:13 Done.
63 parser.add_option('-p', '--prefix', 63 parser.add_argument('-p', '--prefix',
64 help='Prefix to set for all sub_package_paths in the ' 64 help='Prefix to set for all sub_package_paths in the '
65 'manifest. If none is specified, the prefix will be ' 65 'manifest. If none is specified, the prefix will be '
66 'removed; i.e. the start of the path will be ' 66 'removed; i.e. the start of the path will be '
67 '"_platform_specific/..."') 67 '"_platform_specific/..."')
68 parser.add_option('-v', '--verbose', 68 parser.add_argument('-v', '--verbose',
69 help='Verbose output', action='store_true') 69 help='Verbose output', action='store_true')
70 70
71 options, args = parser.parse_args(argv) 71 options, args = parser.parse_args(argv)
binji 2014/11/13 23:57:03 options =
Sam Clegg 2014/11/30 17:55:13 Done.
72 if options.verbose: 72 if options.verbose:
73 Trace.verbose = True 73 Trace.verbose = True
74 74
75 if not args: 75 if not args:
binji 2014/11/13 23:57:03 remove
Sam Clegg 2014/11/30 17:55:12 Done.
76 parser.error('Expected manifest file.') 76 parser.error('Expected manifest file.')
77 77
78 manifest = args[0] 78 manifest = args[0]
79 79
80 Trace('Reading %s' % manifest) 80 Trace('Reading %s' % manifest)
81 with open(manifest) as f: 81 with open(manifest) as f:
82 # Keep the dictionary order. This is only supported on Python 2.7+ 82 # Keep the dictionary order. This is only supported on Python 2.7+
83 if sys.version_info >= (2, 7, 0): 83 if sys.version_info >= (2, 7, 0):
84 data = json.load(f, object_pairs_hook=collections.OrderedDict) 84 data = json.load(f, object_pairs_hook=collections.OrderedDict)
85 else: 85 else:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if __name__ == '__main__': 123 if __name__ == '__main__':
124 try: 124 try:
125 rtn = main(sys.argv[1:]) 125 rtn = main(sys.argv[1:])
126 except Error, e: 126 except Error, e:
127 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) 127 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
128 rtn = 1 128 rtn = 1
129 except KeyboardInterrupt: 129 except KeyboardInterrupt:
130 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) 130 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
131 rtn = 1 131 rtn = 1
132 sys.exit(rtn) 132 sys.exit(rtn)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698