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

Side by Side Diff: native_client_sdk/src/tools/create_html.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 6 years, 1 month 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 """Creates simple HTML for running a NaCl module. 6 """Creates simple HTML for running a NaCl module.
7 7
8 This script is designed to make the process of creating running 8 This script is designed to make the process of creating running
9 Native Client executables in the browers simple by creating 9 Native Client executables in the browers simple by creating
10 boilderplate a .html (and optionally a .nmf) file for a given 10 boilderplate a .html (and optionally a .nmf) file for a given
11 Native Client executable (.nexe). 11 Native Client executable (.nexe).
12 12
13 If the script if given a .nexe file it will produce both html 13 If the script if given a .nexe file it will produce both html
14 the nmf files. If it is given an nmf it will only create 14 the nmf files. If it is given an nmf it will only create
15 the html file. 15 the html file.
16 """ 16 """
17 17
18 import optparse 18 import argparse
19 import os 19 import os
20 import sys 20 import sys
21 import subprocess 21 import subprocess
22 22
binji 2014/11/13 23:57:03 add a python 2.7 check? Looks like the docs say 2
Sam Clegg 2014/11/30 17:55:12 Done in separate CL
23 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 23 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
24 HTML_TEMPLATE = '''\ 24 HTML_TEMPLATE = '''\
25 <!DOCTYPE html> 25 <!DOCTYPE html>
26 <!-- 26 <!--
27 Sample html container for embedded NaCl module. This file was auto-generated 27 Sample html container for embedded NaCl module. This file was auto-generated
28 by the create_html tool which is part of the NaCl SDK. 28 by the create_html tool which is part of the NaCl SDK.
29 29
30 The embed tag is setup with PS_STDOUT, PS_STDERR and PS_TTY_PREFIX attributes 30 The embed tag is setup with PS_STDOUT, PS_STDERR and PS_TTY_PREFIX attributes
31 which, for applications linked with ppapi_simple, will cause stdout and stderr 31 which, for applications linked with ppapi_simple, will cause stdout and stderr
32 to be sent to javascript via postMessage. Also, the postMessage listener 32 to be sent to javascript via postMessage. Also, the postMessage listener
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 Log('creating html: %s' % htmlfile) 153 Log('creating html: %s' % htmlfile)
154 with open(htmlfile, 'w') as outfile: 154 with open(htmlfile, 'w') as outfile:
155 args = {} 155 args = {}
156 args['title'] = basename 156 args['title'] = basename
157 args['module_name'] = basename 157 args['module_name'] = basename
158 args['nmf'] = os.path.basename(nmf) 158 args['nmf'] = os.path.basename(nmf)
159 outfile.write(HTML_TEMPLATE % args) 159 outfile.write(HTML_TEMPLATE % args)
160 160
161 161
162 def main(argv): 162 def main(argv):
163 usage = 'Usage: %prog [options] <.nexe/.pexe or .nmf>' 163 parser = argparse.ArgumentParser(description=__doc__)
164 epilog = 'Example: create_html.py -o index.html my_nexe.nexe' 164 parser.add_argument('-v', '--verbose', action='store_true',
165 parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog) 165 help='Verbose output')
166 parser.add_option('-v', '--verbose', action='store_true', 166 parser.add_argument('-d', '--debug-libs', action='store_true',
167 help='Verbose output') 167 help='When calling create_nmf request debug libaries')
168 parser.add_option('-d', '--debug-libs', action='store_true', 168 parser.add_argument('-o', '--output', dest='output',
169 help='When calling create_nmf request debug libaries') 169 help='Name of html file to write (default is '
170 parser.add_option('-o', '--output', dest='output', 170 'input name with .html extension)',
171 help='Name of html file to write (default is ' 171 metavar='FILE')
172 'input name with .html extension)', 172 parser.add_argument('exe', metavar='EXE_OR_NMF', nargs='+',
173 metavar='FILE') 173 help='Executable (.nexe/.pexe) or nmf file to generate '
174 174 'html for.')
175 # To enable bash completion for this command first install optcomplete 175 # To enable bash completion for this command first install optcomplete
176 # and then add this line to your .bashrc: 176 # and then add this line to your .bashrc:
177 # complete -F _optcomplete create_html.py 177 # complete -F _optcomplete create_html.py
178 try: 178 try:
179 import optcomplete 179 import optcomplete
180 optcomplete.autocomplete(parser) 180 optcomplete.autocomplete(parser)
181 except ImportError: 181 except ImportError:
182 pass 182 pass
183 183
184 options, args = parser.parse_args(argv) 184 options = parser.parse_args(argv)
185
186 if not args:
187 parser.error('no input file specified')
188 185
189 if options.verbose: 186 if options.verbose:
190 Log.enabled = True 187 Log.enabled = True
191 188
192 CreateHTML(args, options) 189 CreateHTML(options.exe, options)
193 return 0 190 return 0
194 191
195 192
196 if __name__ == '__main__': 193 if __name__ == '__main__':
197 try: 194 try:
198 rtn = main(sys.argv[1:]) 195 rtn = main(sys.argv[1:])
199 except Error, e: 196 except Error, e:
200 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) 197 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
201 rtn = 1 198 rtn = 1
202 except KeyboardInterrupt: 199 except KeyboardInterrupt:
203 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) 200 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
204 rtn = 1 201 rtn = 1
205 sys.exit(rtn) 202 sys.exit(rtn)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698