Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py |
| diff --git a/chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py b/chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..0fc22cf7a5aa22b84d716cd4a3bb1b04881d417d |
| --- /dev/null |
| +++ b/chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py |
| @@ -0,0 +1,46 @@ |
| +#!/usr/bin/env python |
| + |
| +# Copyright 2014 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. |
| + |
| +import json |
| +import io |
| +import optparse |
| +import os |
| +import sys |
| + |
| +'''Generate an extension manifest based on a template.''' |
| + |
| + |
| +def processJinjaTemplate(input_file, output_file, context): |
| + jinja2_path = os.path.normpath( |
| + os.path.join(os.path.abspath(__file__), |
| + *[os.path.pardir] * 7 + ['third_party/jinja2'])) |
| + sys.path.append(os.path.split(jinja2_path)[0]) |
|
Peter Lundblad
2014/05/23 16:04:27
Why are you including a path component that you la
Peter Lundblad
2014/05/23 16:04:27
I recommend prepending so we pick up our own jinja
David Tseng
2014/05/23 19:16:37
Took this code from remoting; revised.
|
| + import jinja2 |
| + (template_path, template_name) = os.path.split(input_file) |
| + env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path)) |
| + template = env.get_template(template_name) |
| + rendered = template.render(context) |
| + io.open(output_file, 'w', encoding='utf-8').write(rendered).close() |
|
Peter Lundblad
2014/05/23 16:04:27
nit: Why io.open?
Peter Lundblad
2014/05/23 16:04:27
Ho would you feel about quickly loading the result
David Tseng
2014/05/23 19:16:37
Ditto; no I suspect it's because open doesn't let
David Tseng
2014/05/23 19:16:37
Sure. sgtm.
|
| + |
| + |
| +def main(): |
| + parser = optparse.OptionParser(description=__doc__) |
| + parser.usage = '%prog [options] <template_manifest_path>' |
| + parser.add_option( |
| + '-o', '--output_manifest', action='store', metavar='OUTPUT_MANIFEST', |
| + help='File to place generated manifest') |
| + parser.add_option( |
| + '-g', '--is_guest_manifest', action='store', metavar='GUEST_MANIFEST', |
| + help='Generate a guest mode capable manifest') |
| + |
| + options, args = parser.parse_args() |
| + if len(args) != 1: |
| + print >>sys.stderr, 'Expected exactly one argument' |
| + sys.exit(1) |
| + processJinjaTemplate(args[0], options.output_manifest, parser.values.__dict__) |
|
Peter Lundblad
2014/05/23 16:04:27
What is parser.values.__dict__ for?
David Tseng
2014/05/23 19:16:37
Allows us to pass the jinja2 "renderer" all option
|
| + |
| +if __name__ == '__main__': |
| + main() |