Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Extracts information from a library.dsc file.""" | |
| 7 | |
| 8 import optparse | |
| 9 import os | |
| 10 import sys | |
| 11 | |
| 12 import parse_dsc | |
| 13 | |
| 14 def Error(msg): | |
| 15 print >> sys.stderr, 'dsc_info: msg' | |
|
binji
2013/11/12 19:41:42
'dsc_info: %s' % msg
| |
| 16 sys.exit(1) | |
| 17 | |
|
binji
2013/11/12 19:41:42
nit: two lines between top-level functions
| |
| 18 def FindTarget(tree, target_name): | |
| 19 targets = tree['TARGETS'] | |
| 20 for target in targets: | |
| 21 if target['NAME'] == target_name: | |
| 22 return target | |
| 23 Error('Target %s not found' % target_name) | |
| 24 | |
| 25 def GetSources(lib_dir, tree, target_name): | |
| 26 result = [] | |
| 27 target = FindTarget(tree, target_name) | |
| 28 for filename in target['SOURCES']: | |
| 29 result.append('/'.join([lib_dir, filename])) | |
| 30 return result | |
| 31 | |
| 32 def DoMain(argv): | |
|
binji
2013/11/12 19:41:42
we usually just have:
def main(args):
and pass a
| |
| 33 "Entry point for gyp's pymod_do_main command." | |
| 34 parser = optparse.OptionParser(usage='%prog [OPTIONS] LIB_DIR') | |
| 35 parser.add_option('-s', '--sources', | |
| 36 help='Print a list of source for the target', | |
| 37 action='store_true', default=False) | |
| 38 parser.add_option('-t', '--target', | |
|
binji
2013/11/12 19:41:42
use positional args for this instead, and have a o
| |
| 39 help='Target to display information for') | |
| 40 options, args = parser.parse_args(argv) | |
| 41 if len(args) != 1: | |
| 42 parser.error('Wrong numer of arguments') | |
|
binji
2013/11/12 19:41:42
sp: number
| |
| 43 lib_dir = args[0] | |
| 44 tree = parse_dsc.LoadProject(os.path.join(lib_dir, 'library.dsc')) | |
| 45 if options.sources: | |
| 46 if not options.target: | |
| 47 parser.error('Missing --target') | |
| 48 return '\n'.join(GetSources(lib_dir, tree, options.target)) | |
| 49 parser.error('No action specified') | |
| 50 | |
| 51 def main(argv): | |
| 52 print DoMain(argv[1:]) | |
| 53 | |
| 54 if __name__ == '__main__': | |
| 55 sys.exit(main(sys.argv)) | |
|
binji
2013/11/12 19:41:42
for consistency, please add KeyboardInterrupt exce
| |
| OLD | NEW |