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

Side by Side Diff: native_client_sdk/src/doc/doxygen/rst_index.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
« no previous file with comments | « native_client_sdk/src/doc/doxygen/generate_docs.py ('k') | native_client_sdk/src/test_all.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 """Script to generate rst index file doxygen generated html files.
7 """
8
9 import argparse
6 import cStringIO 10 import cStringIO
7 import fnmatch 11 import fnmatch
8 import optparse
9 import os 12 import os
10 import re 13 import re
11 import sys 14 import sys
12 15
13 VALID_CHANNELS = ('stable', 'beta', 'dev') 16 VALID_CHANNELS = ('stable', 'beta', 'dev')
14 17
15 ROOT_FILE_CONTENTS = """\ 18 ROOT_FILE_CONTENTS = """\
16 .. _pepper_%(channel)s_index: 19 .. _pepper_%(channel)s_index:
17 20
18 21
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 223
221 # Use StringIO so we don't write out a partial file on error. 224 # Use StringIO so we don't write out a partial file on error.
222 output = cStringIO.StringIO() 225 output = cStringIO.StringIO()
223 output.write(CPP_FILE_CONTENTS % vars()) 226 output.write(CPP_FILE_CONTENTS % vars())
224 227
225 with open(out_filename, 'w') as f: 228 with open(out_filename, 'w') as f:
226 f.write(output.getvalue()) 229 f.write(output.getvalue())
227 230
228 231
229 def main(argv): 232 def main(argv):
230 usage = 'Usage: %prog [options] <--root|--c|--cpp> directory' 233 parser = argparse.ArgumentParser(description=__doc__)
231 parser = optparse.OptionParser(usage=usage) 234 parser.add_argument('--channel', help='pepper channel (stable, beta, dev)')
232 parser.add_option('--channel', help='pepper channel (stable, beta, dev)') 235 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.)') 236 parser.add_argument('--root', help='Generate root API index',
234 parser.add_option('--root', help='Generate root API index', 237 action='store_true', default=False)
235 action='store_true', default=False) 238 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', 239 default=False)
237 default=False) 240 parser.add_argument('--cpp', help='Generate C++ API index',
238 parser.add_option('--cpp', help='Generate C++ API index', action='store_true', 241 action='store_true', default=False)
239 default=False) 242 parser.add_argument('directory', help='input directory')
240 parser.add_option('-o', '--output', help='output file.') 243 parser.add_argument('output_file', help='output file')
241 options, files = parser.parse_args(argv) 244 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 245
249 if options.channel not in VALID_CHANNELS: 246 if options.channel not in VALID_CHANNELS:
250 parser.error('Expected channel to be one of %s' % ', '.join(VALID_CHANNELS)) 247 parser.error('Expected channel to be one of %s' % ', '.join(VALID_CHANNELS))
251 248
252 if sum((options.c, options.cpp, options.root)) != 1: 249 if sum((options.c, options.cpp, options.root)) != 1:
253 parser.error('Exactly one of --c/--cpp/--root flags is required.') 250 parser.error('Exactly one of --c/--cpp/--root flags is required.')
254 251
255 root_dir = files[0]
256 252
257 if options.c: 253 if options.c:
258 GenerateCIndex(root_dir, options.channel, options.version, options.output) 254 GenerateCIndex(options.directory, options.channel, options.version,
255 options.output_file)
259 elif options.cpp: 256 elif options.cpp:
260 GenerateCppIndex(root_dir, options.channel, options.version, options.output) 257 GenerateCppIndex(options.directory, options.channel, options.version,
258 options.output_file)
261 elif options.root: 259 elif options.root:
262 GenerateRootIndex(options.channel, options.version, options.output) 260 GenerateRootIndex(options.channel, options.version,
261 options.output_file)
263 else: 262 else:
264 assert(False) 263 assert(False)
265 return 0 264 return 0
266 265
267 266
268 if __name__ == '__main__': 267 if __name__ == '__main__':
269 try: 268 try:
270 rtn = main(sys.argv[1:]) 269 rtn = main(sys.argv[1:])
271 except KeyboardInterrupt: 270 except KeyboardInterrupt:
272 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) 271 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
273 rtn = 1 272 rtn = 1
274 sys.exit(rtn) 273 sys.exit(rtn)
OLDNEW
« no previous file with comments | « native_client_sdk/src/doc/doxygen/generate_docs.py ('k') | native_client_sdk/src/test_all.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698