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

Side by Side Diff: native_client_sdk/src/build_tools/verify_filelist.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 5 years, 11 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 (c) 2013 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2013 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 import optparse 6 import argparse
7 import os 7 import os
8 import re 8 import re
9 import sys 9 import sys
10 10
11 import build_version 11 import build_version
12 from build_paths import SDK_SRC_DIR, SCRIPT_DIR, OUT_DIR 12 from build_paths import SDK_SRC_DIR, SCRIPT_DIR, OUT_DIR
13 13
14 # Add SDK make tools scripts to the python path. 14 # Add SDK make tools scripts to the python path.
15 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools')) 15 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
16 16
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 line2 = SplitPattern(line2)[0].lower() 175 line2 = SplitPattern(line2)[0].lower()
176 return cmp(line1, line2) 176 return cmp(line1, line2)
177 177
178 lines.sort(compare) 178 lines.sort(compare)
179 with open(rule_path, 'w') as output: 179 with open(rule_path, 'w') as output:
180 for line in lines: 180 for line in lines:
181 output.write(line) 181 output.write(line)
182 182
183 183
184 def main(args): 184 def main(args):
185 parser = optparse.OptionParser(usage='%prog <rule file> <directory>') 185 parser = argparse.ArgumentParser(description=__doc__)
186 parser.add_option('-p', '--platform', 186 parser.add_argument('-p', '--platform',
187 help='Test with this platform, instead of the system\'s platform') 187 help='Test with this platform, instead of the system\'s platform')
188 parser.add_option('-s', '--sort', action='store_true', 188 parser.add_argument('-s', '--sort', action='store_true',
189 help='Sort the file list in place, rather than verifying the contents.') 189 help='Sort the file list in place, rather than verifying the contents.')
190 options, args = parser.parse_args(args) 190 parser.add_argument('rule_file', nargs='?',
191 191 default=os.path.join(SCRIPT_DIR, 'sdk_files.list'))
192 if not args: 192 parser.add_argument('directory_path', nargs='?')
193 args = [os.path.join(SCRIPT_DIR, 'sdk_files.list')] 193 options = parser.parse_args(args)
194 194
195 if options.sort: 195 if options.sort:
196 if not args: 196 SortFile(options.rule_file)
197 parser.error('Expected rule file.')
198 SortFile(args[0])
199 return 0 197 return 0
200 198
201 if len(args) < 2: 199 if not options.directory_path:
202 version = build_version.ChromeMajorVersion() 200 version = build_version.ChromeMajorVersion()
203 args.append(os.path.join(OUT_DIR, 'pepper_%s' % version)) 201 options.directory_path = os.path.join(OUT_DIR, 'pepper_%s' % version)
204 202
205 rule_path = args[0]
206 directory_path = args[1]
207 if options.platform: 203 if options.platform:
208 if options.platform not in VALID_PLATFORMS: 204 if options.platform not in VALID_PLATFORMS:
209 parser.error('Unknown platform: %s' % options.platform) 205 parser.error('Unknown platform: %s' % options.platform)
210 platform = options.platform 206 platform = options.platform
211 else: 207 else:
212 platform = getos.GetPlatform() 208 platform = getos.GetPlatform()
213 209
214 try: 210 try:
215 return Verify(rule_path, directory_path, platform) 211 return Verify(options.rule_file, options.directory_path, platform)
216 except ParseException, e: 212 except ParseException, e:
217 print >> sys.stderr, 'Error parsing rules:\n', e 213 sys.stderr.write('Error parsing rules:\n%s\n' % e)
218 return 1 214 return 1
219 except VerifyException, e: 215 except VerifyException, e:
220 print >> sys.stderr, 'Error verifying file list:\n', e 216 sys.stderr.write('Error verifying file list:\n%s\n' % e)
221 return 1 217 return 1
222 return 0 218 return 0
223 219
224 220
225 if __name__ == '__main__': 221 if __name__ == '__main__':
226 sys.exit(main(sys.argv[1:])) 222 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « native_client_sdk/src/build_tools/update_sdktools.py ('k') | native_client_sdk/src/build_tools/verify_ppapi.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698