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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py

Issue 295123002: Provide script/gypi support for manifest generation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import json
8 import io
9 import optparse
10 import os
11 import sys
12
13 jinja2_path = os.path.normpath(os.path.join(os.path.abspath(__file__),
14 *[os.path.pardir] * 7 + ['third_party']))
15 nom_path = os.path.normpath(os.path.join(os.path.abspath(__file__),
16 *[os.path.pardir] * 7 + ['tools/json_comment_eater']))
17 sys.path.insert(0, jinja2_path)
18 sys.path.insert(0, nom_path)
19 import jinja2
20 from json_comment_eater import Nom
21
22
23 '''Generate an extension manifest based on a template.'''
24
25
26 def processJinjaTemplate(input_file, output_file, context):
27 (template_path, template_name) = os.path.split(input_file)
28 env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path))
29 template = env.get_template(template_name)
30 rendered = template.render(context)
31 rendered_without_comments = Nom(rendered)
32 # Simply for validation
Peter Lundblad 2014/05/23 22:37:19 nit: Sentences end with a period.
David Tseng 2014/05/23 22:57:16 Done.
33 json.loads(rendered_without_comments)
34 with io.open(output_file, 'w', encoding='utf-8') as manifest_file:
35 manifest_file.write(rendered_without_comments)
36
37
38 def main():
39 parser = optparse.OptionParser(description=__doc__)
40 parser.usage = '%prog [options] <template_manifest_path>'
41 parser.add_option(
42 '-o', '--output_manifest', action='store', metavar='OUTPUT_MANIFEST',
43 help='File to place generated manifest')
44 parser.add_option(
45 '-g', '--is_guest_manifest', action='store', metavar='GUEST_MANIFEST',
46 help='Generate a guest mode capable manifest')
47
48 options, args = parser.parse_args()
49 if len(args) != 1:
50 print >>sys.stderr, 'Expected exactly one argument'
51 sys.exit(1)
52 processJinjaTemplate(args[0], options.output_manifest, parser.values.__dict__)
53
54 if __name__ == '__main__':
55 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698