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

Side by Side Diff: native_client_sdk/src/build_tools/dsc_info.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 2013 The Chromium Authors. All rights reserved. 2 # Copyright 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 """Extracts information from a library.dsc file.""" 6 """Extracts information from a library.dsc file."""
7 7
8 import optparse 8 import argparse
9 import os 9 import os
10 import sys 10 import sys
11 11
12 import parse_dsc 12 import parse_dsc
13 13
14 def Error(msg): 14 def Error(msg):
15 print >> sys.stderr, 'dsc_info: %s' % msg 15 print >> sys.stderr, 'dsc_info: %s' % msg
16 sys.exit(1) 16 sys.exit(1)
17 17
18 18
19 def FindTarget(tree, target_name): 19 def FindTarget(tree, target_name):
20 targets = tree['TARGETS'] 20 targets = tree['TARGETS']
21 for target in targets: 21 for target in targets:
22 if target['NAME'] == target_name: 22 if target['NAME'] == target_name:
23 return target 23 return target
24 Error('Target %s not found' % target_name) 24 Error('Target %s not found' % target_name)
25 25
26 26
27 def GetSources(lib_dir, tree, target_name): 27 def GetSources(lib_dir, tree, target_name):
28 result = [] 28 result = []
29 target = FindTarget(tree, target_name) 29 target = FindTarget(tree, target_name)
30 for filename in target['SOURCES']: 30 for filename in target['SOURCES']:
31 result.append('/'.join([lib_dir, filename])) 31 result.append('/'.join([lib_dir, filename]))
32 return result 32 return result
33 33
34 34
35 def DoMain(argv): 35 def DoMain(args):
36 "Entry point for gyp's pymod_do_main command." 36 """Entry point for gyp's pymod_do_main command."""
37 parser = optparse.OptionParser(usage='%prog: [OPTIONS] TARGET') 37 parser = argparse.ArgumentParser(description=__doc__)
38 # Give a clearer error message when this is used as a module. 38 # Give a clearer error message when this is used as a module.
39 parser.prog = 'dsc_info' 39 parser.prog = 'dsc_info'
40 parser.add_option('-s', '--sources', 40 parser.add_argument('-s', '--sources',
41 help='Print a list of source files for the target', 41 help='Print a list of source files for the target',
42 action='store_true', default=False) 42 action='store_true', default=False)
43 parser.add_option('-l', '--libdir', 43 parser.add_argument('-l', '--libdir',
44 help='Directory where the library.dsc file is located', 44 help='Directory where the library.dsc file is located',
45 metavar='DIR') 45 metavar='DIR')
46 options, args = parser.parse_args(argv) 46 parser.add_argument('target')
47 if len(args) != 1: 47 options = parser.parse_args(args)
48 parser.error('Expecting exactly one argument.')
49 target = args[0]
50 libdir = options.libdir or '' 48 libdir = options.libdir or ''
51 tree = parse_dsc.LoadProject(os.path.join(libdir, 'library.dsc')) 49 tree = parse_dsc.LoadProject(os.path.join(libdir, 'library.dsc'))
52 if options.sources: 50 if options.sources:
53 return '\n'.join(GetSources(libdir, tree, target)) 51 return '\n'.join(GetSources(libdir, tree, options.target))
54 parser.error('No action specified') 52 parser.error('No action specified')
55 53
56 54
57 def main(args): 55 def main(args):
58 print DoMain(args) 56 print DoMain(args)
59 57
60 58
61 if __name__ == '__main__': 59 if __name__ == '__main__':
62 try: 60 try:
63 sys.exit(main(sys.argv[1:])) 61 sys.exit(main(sys.argv[1:]))
64 except KeyboardInterrupt: 62 except KeyboardInterrupt:
65 Error('interrupted') 63 Error('interrupted')
OLDNEW
« no previous file with comments | « native_client_sdk/src/build_tools/dsc2gyp.py ('k') | native_client_sdk/src/build_tools/easy_template.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698