Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 import cStringIO | 6 import cStringIO |
| 7 import fnmatch | 7 import fnmatch |
| 8 import optparse | 8 import argparse |
|
binji
2014/11/13 23:57:02
sort
Sam Clegg
2014/11/30 17:55:12
Done.
| |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 VALID_CHANNELS = ('stable', 'beta', 'dev') | 13 VALID_CHANNELS = ('stable', 'beta', 'dev') |
| 14 | 14 |
| 15 ROOT_FILE_CONTENTS = """\ | 15 ROOT_FILE_CONTENTS = """\ |
| 16 .. _pepper_%(channel)s_index: | 16 .. _pepper_%(channel)s_index: |
| 17 | 17 |
| 18 | 18 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 | 220 |
| 221 # Use StringIO so we don't write out a partial file on error. | 221 # Use StringIO so we don't write out a partial file on error. |
| 222 output = cStringIO.StringIO() | 222 output = cStringIO.StringIO() |
| 223 output.write(CPP_FILE_CONTENTS % vars()) | 223 output.write(CPP_FILE_CONTENTS % vars()) |
| 224 | 224 |
| 225 with open(out_filename, 'w') as f: | 225 with open(out_filename, 'w') as f: |
| 226 f.write(output.getvalue()) | 226 f.write(output.getvalue()) |
| 227 | 227 |
| 228 | 228 |
| 229 def main(argv): | 229 def main(argv): |
| 230 usage = 'Usage: %prog [options] <--root|--c|--cpp> directory' | 230 parser = argparse.ArgumentParser(description=__doc__) |
|
binji
2014/11/13 23:57:02
no doc?
Sam Clegg
2014/11/30 17:55:12
Done.
| |
| 231 parser = optparse.OptionParser(usage=usage) | 231 parser.add_argument('--channel', help='pepper channel (stable, beta, dev)') |
| 232 parser.add_option('--channel', help='pepper channel (stable, beta, dev)') | 232 parser.add_argument('--version', help='pepper version (e.g. 32, 33, etc.)') |
| 233 parser.add_option('--version', help='pepper version (e.g. 32, 33, 34, etc.)') | 233 parser.add_argument('--root', help='Generate root API index', |
| 234 parser.add_option('--root', help='Generate root API index', | 234 action='store_true', default=False) |
| 235 action='store_true', default=False) | 235 parser.add_argument('--c', help='Generate C API index', action='store_true', |
| 236 parser.add_option('--c', help='Generate C API index', action='store_true', | 236 default=False) |
| 237 default=False) | 237 parser.add_argument('--cpp', help='Generate C++ API index', |
| 238 parser.add_option('--cpp', help='Generate C++ API index', action='store_true', | 238 action='store_true', default=False) |
| 239 default=False) | 239 parser.add_argument('directory', help='input directory') |
| 240 parser.add_option('-o', '--output', help='output file.') | 240 parser.add_argument('output_file', help='output file') |
| 241 options, files = parser.parse_args(argv) | 241 options = parser.parse_args(argv) |
| 242 | |
| 243 if len(files) != 1: | |
| 244 parser.error('Expected one directory') | |
| 245 | |
| 246 if not options.output: | |
| 247 parser.error('Need output file') | |
| 248 | 242 |
| 249 if options.channel not in VALID_CHANNELS: | 243 if options.channel not in VALID_CHANNELS: |
| 250 parser.error('Expected channel to be one of %s' % ', '.join(VALID_CHANNELS)) | 244 parser.error('Expected channel to be one of %s' % ', '.join(VALID_CHANNELS)) |
| 251 | 245 |
| 252 if sum((options.c, options.cpp, options.root)) != 1: | 246 if sum((options.c, options.cpp, options.root)) != 1: |
| 253 parser.error('Exactly one of --c/--cpp/--root flags is required.') | 247 parser.error('Exactly one of --c/--cpp/--root flags is required.') |
| 254 | 248 |
| 255 root_dir = files[0] | |
| 256 | 249 |
| 257 if options.c: | 250 if options.c: |
| 258 GenerateCIndex(root_dir, options.channel, options.version, options.output) | 251 GenerateCIndex(options.directory, options.channel, options.version, |
| 252 options.output_file) | |
| 259 elif options.cpp: | 253 elif options.cpp: |
| 260 GenerateCppIndex(root_dir, options.channel, options.version, options.output) | 254 GenerateCppIndex(options.directory, options.channel, options.version, |
| 255 options.output_file) | |
| 261 elif options.root: | 256 elif options.root: |
| 262 GenerateRootIndex(options.channel, options.version, options.output) | 257 GenerateRootIndex(options.channel, options.version, |
| 258 options.output_file) | |
| 263 else: | 259 else: |
| 264 assert(False) | 260 assert(False) |
| 265 return 0 | 261 return 0 |
| 266 | 262 |
| 267 | 263 |
| 268 if __name__ == '__main__': | 264 if __name__ == '__main__': |
| 269 try: | 265 try: |
| 270 rtn = main(sys.argv[1:]) | 266 rtn = main(sys.argv[1:]) |
| 271 except KeyboardInterrupt: | 267 except KeyboardInterrupt: |
| 272 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) | 268 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) |
| 273 rtn = 1 | 269 rtn = 1 |
| 274 sys.exit(rtn) | 270 sys.exit(rtn) |
| OLD | NEW |