From cd620f78098c40d38c56a72e2c859565c283c412 Mon Sep 17 00:00:00 2001 From: "sbc@chromium.org" Date: Wed, 12 Jun 2013 00:20:15 +0000 Subject: [NaCl SDK] Add tool for creating html scaffolding. This tool can create and basic html page for a nexe as well as calling create_nmf to create the nmf. It can be given a .nexe or a .nmf file. BUG=243407 R=binji@chromium.org Review URL: https://codereview.chromium.org/16599018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205682 0039d316-1c4b-4281-b951-d872f2087c98 --- native_client_sdk/src/tools/create_html.py | 177 +++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100755 native_client_sdk/src/tools/create_html.py (limited to 'native_client_sdk/src/tools/create_html.py') diff --git a/native_client_sdk/src/tools/create_html.py b/native_client_sdk/src/tools/create_html.py new file mode 100755 index 0000000..b981aac --- /dev/null +++ b/native_client_sdk/src/tools/create_html.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Script for creating HTML needed to run a NaCl module. + +This script is designed to make the process of creating running +Native Client executables in the browers simple by creating +boilderplate a .html (and optionally a .nmf) file for a given +Native Client executable (.nexe). + +If the script if given a .nexe file it will produce both html +the nmf files. If it is given an nmf it will only create +the html file. +""" + +import optparse +import os +import sys +import subprocess + +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +HTML_TEMPLATE = '''\ + + + + + + + %(title)s + + + +

Native Client Module: %(module_name)s

+

Status: Loading

+ +
+ +
+ +

Standard output/error:

+ + + + + +''' + + +class Error(Exception): + pass + + +def Log(msg): + if Log.enabled: + sys.stderr.write(str(msg) + '\n') +Log.enabled = False + + +def CreateHTML(filename, options): + if not os.path.exists(filename): + raise Error('file not found: %s' % filename) + + if not os.path.isfile(filename): + raise Error('specified input is not a file: %s' % filename) + + basename, ext = os.path.splitext(filename) + if ext not in ('.nexe', '.pexe', '.nmf'): + raise Error('input file must be .nexe, .pexe or .nmf: %s' % filename) + + if ext in ('.nexe', '.pexe'): + nmf = basename + '.nmf' + Log('creating nmf: %s' % nmf) + create_nmf = os.path.join(SCRIPT_DIR, 'create_nmf.py') + staging = os.path.dirname(nmf) + if not staging: + staging = '.' + cmd = [create_nmf, '-s', staging, '-o', nmf, filename] + if options.verbose: + cmd.append('-v') + Log(cmd) + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError: + raise Error('create_nmf failed') + else: + nmf = filename + + htmlfile = options.output + if not htmlfile: + htmlfile = basename + '.html' + + Log('creating html: %s' % htmlfile) + with open(htmlfile, 'w') as outfile: + args = {} + args['title'] = basename + args['module_name'] = basename + args['nmf'] = nmf + outfile.write(HTML_TEMPLATE % args) + + +def main(argv): + usage = 'Usage: %prog [options] <.nexe/.pexe or .nmf>' + parser = optparse.OptionParser(usage) + parser.add_option('-v', '--verbose', action='store_true', + help='Verbose output') + parser.add_option('-o', '--output', dest='output', + help='Name of html file to write (default is ' + 'input name with .html extension)', + metavar='FILE') + + options, args = parser.parse_args(argv) + if len(args) > 1: + parser.error('more than one input file specified') + + if not args: + parser.error('no input file specified') + + if options.verbose: + Log.enabled = True + + CreateHTML(args[0], options) + return 0 + + +if __name__ == '__main__': + try: + rtn = main(sys.argv[1:]) + except Error, e: + sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) + rtn = 1 + except KeyboardInterrupt: + sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) + rtn = 1 + sys.exit(rtn) -- cgit v1.1